/** * @param string $label * * @return Tag */ protected function getOrCreateTag($label) { if (isset($this->tagFirstLevelCache[$label])) { return $this->tagFirstLevelCache[$label]; } $tag = $this->tagRepository->findOneByLabel($label); if ($tag === null) { $tag = new Tag($label); $this->tagRepository->add($tag); } $this->tagFirstLevelCache[$label] = $tag; return $tag; }
/** * @param string $label * @return void * @Flow\Validate(argumentName="label", type="NotEmpty") * @Flow\Validate(argumentName="label", type="Label") */ public function createTagAction($label) { $existingTag = $this->tagRepository->findOneByLabel($label); if ($existingTag !== null) { if (($assetCollection = $this->browserState->get('activeAssetCollection')) !== null && $assetCollection->addTag($existingTag)) { $this->assetCollectionRepository->update($assetCollection); $this->addFlashMessage('tagAlreadyExistsAndAddedToCollection', '', Message::SEVERITY_OK, [htmlspecialchars($label)]); } } else { $tag = new Tag($label); $this->tagRepository->add($tag); if (($assetCollection = $this->browserState->get('activeAssetCollection')) !== null && $assetCollection->addTag($tag)) { $this->assetCollectionRepository->update($assetCollection); } $this->addFlashMessage('tagHasBeenCreated', '', Message::SEVERITY_OK, [htmlspecialchars($label)]); } $this->redirect('index'); }
/** * @param string $label * @return void * @Flow\Validate(argumentName="label", type="NotEmpty") * @Flow\Validate(argumentName="label", type="Label") */ public function createTagAction($label) { $existingTag = $this->tagRepository->findOneByLabel($label); if ($existingTag !== null) { if (($assetCollection = $this->browserState->get('activeAssetCollection')) !== null && $assetCollection->addTag($existingTag)) { $this->assetCollectionRepository->update($assetCollection); $this->addFlashMessage(sprintf('Tag "%s" already exists and was added to collection.', htmlspecialchars($label))); } } else { $tag = new Tag($label); $this->tagRepository->add($tag); if (($assetCollection = $this->browserState->get('activeAssetCollection')) !== null && $assetCollection->addTag($tag)) { $this->assetCollectionRepository->update($assetCollection); } $this->addFlashMessage(sprintf('Tag "%s" has been created.', htmlspecialchars($label))); } $this->redirect('index'); }
/** * @param NodeInterface $node * @param Image $newImage * @param string $title * @param string|array $tagLabel * @param string $propertyName * @param boolean $removePreviousProfileImage * @return NodeInterface */ public function setImageToNode(NodeInterface $node, Image $newImage, $title, $tagLabel = NULL, $propertyName = 'image', $removePreviousProfileImage = FALSE) { $newImage->setTitle($title); if ($tagLabel !== NULL) { if (is_array($tagLabel) && !is_string($tagLabel)) { if ($removePreviousProfileImage === TRUE) { $this->removePreviousProfilePictureBasedOnTags($title, $tagLabel); } foreach ($tagLabel as $key => $label) { $tag = $this->tagRepository->findOneByLabel($label); if (!$tag instanceof Tag) { $tag = new Tag($label); $this->tagRepository->add($tag); } $newImage->addTag($tag); } } elseif (is_string($tagLabel) && !is_array($tagLabel)) { $tag = $this->tagRepository->findOneByLabel($tagLabel); if (!$tag instanceof Tag) { $tag = new Tag($tagLabel); $this->tagRepository->add($tag); } $newImage->addTag($tag); } } /** @var Image $image */ $image = $this->imageRepository->findByIdentifier($newImage->getIdentifier()); if ($image !== NULL) { try { $this->imageRepository->update($image); $node->setProperty($propertyName, $image); } catch (\Exception $exception) { // Image repository might give back an image while not stored for some reason. If so, catch that error and store it anyway $image->setTitle($title); $this->imageRepository->add($image); $node->setProperty($propertyName, $image); $this->systemLogger->log('Image with identifier ' . $image->getIdentifier() . ' stored while preceding an error that is not stored yet fetched using ImageRepository', LOG_CRIT); } } else { $this->imageRepository->add($newImage); $node->setProperty($propertyName, $newImage); } return $node; }