/** * @param PersistEvent $event * * @throws DocumentManagerException */ public function handlePersist(PersistEvent $event) { $document = $event->getDocument(); if (!$document instanceof AutoNameBehavior) { return; } $title = $document->getTitle(); if (!$title) { throw new DocumentManagerException(sprintf('Document has no title (title is required for auto name behavior): %s)', DocumentHelper::getDebugTitle($document))); } $name = $this->slugifier->slugify($title); $parentNode = $event->getParentNode(); $node = $event->hasNode() ? $event->getNode() : null; $name = $this->resolver->resolveName($parentNode, $name, $node); if (null === $node) { $node = $this->documentStrategy->createNodeForDocument($document, $parentNode, $name); $event->setNode($node); return; } if ($name === $node->getName()) { return; } $node = $event->getNode(); $defaultLocale = $this->registry->getDefaultLocale(); if ($defaultLocale != $event->getLocale()) { return; } $this->rename($node, $name); }
/** * @param PersistEvent $event * * @throws DocumentManagerException */ public function handlePersist(PersistEvent $event) { $options = $event->getOptions(); $this->validateOptions($options); $document = $event->getDocument(); $parentPath = null; $nodeName = null; if ($options['path']) { $parentPath = PathHelper::getParentPath($options['path']); $nodeName = PathHelper::getNodeName($options['path']); } if ($options['parent_path']) { $parentPath = $options['parent_path']; } if ($parentPath) { $event->setParentNode($this->resolveParent($parentPath, $options)); } if ($options['node_name']) { if (!$event->hasParentNode()) { throw new DocumentManagerException(sprintf('The "node_name" option can only be used either with the "parent_path" option ' . 'or when a parent node has been established by a previous subscriber. ' . 'When persisting document: %s', DocumentHelper::getDebugTitle($document))); } $nodeName = $options['node_name']; } if (!$nodeName) { return; } if ($event->hasNode()) { $this->renameNode($event->getNode(), $nodeName); return; } $node = $this->strategy->createNodeForDocument($document, $event->getParentNode(), $nodeName); $event->setNode($node); }
/** * {@inheritdoc} */ public function getMetadataForPhpcrNode(NodeInterface $node) { $metadata = $this->strategy->resolveMetadataForNode($node); if (null !== $metadata) { return $metadata; } return $this->getUnknownMetadata(); }