30 $entity = $this->findByType($type);
34 'Collection {%s} already contains {%s} entity.', static::class, $type
39 $image = $this->factory->createEntity($type);
70 protected function findByType(
string $type): ?
BaseImage
75 if ($item instanceof $type)
94 $morePhotos[] = $item;
101 public function getFrontImage(): ?
BaseImage
104 if (!$picture->isNew())
110 if (!$picture->isNew())
118 return !$picture->isNew() ? $picture :
null;
121 public function getValues(): array
128 $values[] = $image->isNew() ? $image->getFileStructure() : $image->getId();
140 $this->removeOldValues($values);
148 foreach ($this->prepareValues($values) as $value)
150 if (is_array($value))
166 $entity = $this->
create();
167 $entity->setFileStructure($value);
170 private function prepareValues(array $values): array
172 if (isset($values[
'name']) || isset($values[
'tmp_name']))
180 private function removeOldValues(array $values): void
184 foreach ($this->prepareValues($values) as $value)
186 if (!empty($value) && is_numeric($value))
188 $valuesToSave[] = (int)$value;
194 if ($entity->isNew() || !in_array($entity->getId(), $valuesToSave,
true))