Sulu\Bundle\TagBundle\Tag\TagManagerInterface::findOrCreateByName PHP Method

findOrCreateByName() public method

Loads the tag with the given name, or creates it, if it does not exist.
public findOrCreateByName ( string $name, integer $userId ) : Tag
$name string The name to find or create
$userId integer The id of the user who tries to find a tag
return Sulu\Bundle\TagBundle\Entity\Tag
    public function findOrCreateByName($name, $userId);

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 public function write(NodeInterface $node, PropertyInterface $property, $userId, $webspaceKey, $languageCode, $segmentKey)
 {
     $tagIds = [];
     $tags = $property->getValue() === null ? [] : $property->getValue();
     foreach ($tags as $tag) {
         $tagIds[] = $this->tagManager->findOrCreateByName($tag, $userId)->getId();
     }
     $node->setProperty($property->getName(), $tagIds);
 }
All Usage Examples Of Sulu\Bundle\TagBundle\Tag\TagManagerInterface::findOrCreateByName