/** * Generate a node with a unique name. * * @param NodeType $nodeType * @param Translation $translation * @param Node|null $parent * @param Tag|null $tag * @param boolean $pushToTop * * @return RZ\Roadiz\Core\Entities\NodesSources */ public function generate(NodeType $nodeType, Translation $translation, Node $parent = null, Tag $tag = null, $pushToTop = false) { $name = $nodeType->getDisplayName() . " " . uniqid(); $node = new Node($nodeType); $node->setParent($parent); $node->setNodeName($name); if (null !== $tag) { $node->addTag($tag); } $this->entityManager->persist($node); if ($pushToTop) { $node->setPosition(0.5); } $sourceClass = "GeneratedNodeSources\\" . $nodeType->getSourceEntityClassName(); $source = new $sourceClass($node, $translation); $source->setTitle($name); $this->entityManager->persist($source); $this->entityManager->flush(); return $source; }
/** * Link a node with a tag. * * @param array $data * @param RZ\Roadiz\Core\Entities\Node $node */ protected function addNodeTag($data, Node $node) { if (!empty($data['tagPaths'])) { $paths = explode(',', $data['tagPaths']); $paths = array_filter($paths); foreach ($paths as $path) { $tag = $this->getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\Tag')->findOrCreateByPath($path); $node->addTag($tag); } } $this->getService('em')->flush(); }