Example #1
0
 /**
  * Update nodeName when title is available.
  *
  * @param  string       $title
  * @param  NodesSources $nodeSource
  */
 protected function updateNodeName(NodesSources $nodeSource)
 {
     $title = $nodeSource->getTitle();
     /*
      * update node name if dynamic option enabled and
      * default translation
      */
     if ("" != $title && true === $nodeSource->getNode()->isDynamicNodeName() && $nodeSource->getTranslation()->isDefaultTranslation()) {
         $testingNodeName = StringHandler::slugify($title);
         /*
          * node name wont be updated if name already taken
          */
         if ($testingNodeName != $nodeSource->getNode()->getNodeName() && false === (bool) $this->getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\UrlAlias')->exists($testingNodeName) && false === (bool) $this->getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\Node')->exists($testingNodeName)) {
             $nodeSource->getNode()->setNodeName($title);
             $this->getService('em')->flush();
             /*
              * Dispatch event
              */
             $event = new FilterNodeEvent($nodeSource->getNode());
             $this->getService('dispatcher')->dispatch(NodeEvents::NODE_UPDATED, $event);
         }
     }
 }
 /**
  * Get node-source parent according to its translation.
  *
  * @param  NodesSources $nodeSource
  * @return NodesSources|null
  */
 public function findParent(NodesSources $nodeSource)
 {
     if (null !== $nodeSource->getNode()->getParent()) {
         try {
             $query = $this->_em->createQuery('
                 SELECT ns FROM RZ\\Roadiz\\Core\\Entities\\NodesSources ns
                 WHERE ns.node = :node
                 AND ns.translation = :translation')->setParameter('node', $nodeSource->getNode()->getParent())->setParameter('translation', $nodeSource->getTranslation());
             return $query->getSingleResult();
         } catch (NoResultException $e) {
             return null;
         }
     } else {
         return null;
     }
 }