33 public function setValues(array $values): self
36 $currentValues = $this->getValues();
37 $filteredValues = $this->filterValues($values);
39 $oldValuesToRemove = array_diff($currentValues, $filteredValues);
41 if (!empty($oldValuesToRemove))
48 if (in_array($item->getValue(), $oldValuesToRemove,
true))
50 $oldSections[] = $item;
54 $this->
remove(...$oldSections);
57 $newValuesToAdd = array_diff($filteredValues, $currentValues);
59 if (!empty($newValuesToAdd))
63 foreach ($newValuesToAdd as $value)
65 $newSections[] = $this
72 $this->
add(...$newSections);
78 public function getValues(): array
85 $values[] = $item->getValue();
91 private function filterValues(array $values): array
95 foreach ($values as $value)
97 if (is_numeric($value))
99 $filteredValues[] = (int)$value;
103 return array_unique($filteredValues);
112 $res = $this->repository->save(...$this->
getIterator());
114 if ($res->isSuccess())
120 $result->addErrors($res->getErrors());