public addTag ( |
||
$tagEntity |
/** * Data can be set over by array. * * @param $media * @param $data * @param UserInterface $user * * @return Media */ protected function setDataToMedia(Media $media, $data, $user) { foreach ($data as $attribute => $value) { if ($value || $attribute === 'tags' && $value !== null || $attribute === 'size' && $value !== null || $attribute === 'description' && $value !== null || $attribute === 'copyright' && $value !== null) { switch ($attribute) { case 'size': $media->setSize($value); break; case 'title': $media->setTitle($value); break; case 'description': $media->setDescription($value); break; case 'copyright': $media->setCopyright($value); break; case 'version': $media->setVersion($value); break; case 'name': $media->setName($value); break; case 'url': $media->setUrl($value); break; case 'formats': $media->setFormats($value); break; case 'storageOptions': $media->setStorageOptions($value); break; case 'publishLanguages': $media->setPublishLanguages($value); break; case 'contentLanguages': $media->setContentLanguages($value); break; case 'tags': $media->removeTags(); if (count($value)) { foreach ($value as $tag) { $tagEntity = $this->tagManager->findOrCreateByName($tag, $user->getId()); $media->addTag($tagEntity); } } break; case 'properties': $media->setProperties($value); break; case 'changed': $media->setChanged($value); break; case 'created': break; case 'changer': if ($value instanceof UserInterface) { $media->setChanger($value); } break; case 'creator': if ($value instanceof UserInterface) { $media->setCreator($value); } break; case 'mimeType': $media->setMimeType($value); break; case 'collection': $collectionEntity = $this->getCollectionById($value); $media->setCollection($collectionEntity); // set parent break; case 'type': if (isset($value['id'])) { $type = $this->typeManager->get($value['id']); $media->setType($type); } break; } } } return $media; }