/**
  * @param NodesSources $nodeSource
  * @param string $themeName
  * @param array $assignation
  *
  * @return string
  */
 public function blockRender(NodesSources $nodeSource, $themeName = "DefaultTheme", $assignation = [])
 {
     if (null !== $nodeSource) {
         if (!empty($themeName)) {
             $class = '\\Themes\\' . $themeName . '\\Controllers\\Blocks\\' . $nodeSource->getNode()->getNodeType()->getName() . 'Controller';
             if (class_exists($class) && method_exists($class, 'blockAction')) {
                 $ctrl = new $class();
                 $ctrl->setContainer($this->container);
                 $ctrl->__init();
                 $response = $ctrl->blockAction($this->container['request'], $nodeSource, $assignation);
                 return $response->getContent();
             } else {
                 throw new \Exception($class . "::blockAction() action does not exist.", 1);
             }
         } else {
             throw new \Exception("Invalid name formatting for your theme.", 1);
         }
     }
 }
 /**
  * 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;
     }
 }
Example #3
0
 /**
  * Fill node-source content according to field type.
  *
  * @param mixed         $dataValue
  * @param NodesSources  $nodeSource
  * @param NodeTypeField $field
  *
  * @return void
  */
 public function setValueFromFieldType($dataValue, NodesSources $nodeSource, NodeTypeField $field)
 {
     switch ($field->getType()) {
         case NodeTypeField::DOCUMENTS_T:
             $hdlr = $nodeSource->getHandler();
             $hdlr->cleanDocumentsFromField($field);
             if (is_array($dataValue)) {
                 foreach ($dataValue as $documentId) {
                     $tempDoc = Kernel::getService('em')->find('RZ\\Roadiz\\Core\\Entities\\Document', (int) $documentId);
                     if ($tempDoc !== null) {
                         $hdlr->addDocumentForField($tempDoc, $field);
                     }
                 }
             }
             break;
         case NodeTypeField::CUSTOM_FORMS_T:
             $hdlr = $nodeSource->getNode()->getHandler();
             $hdlr->cleanCustomFormsFromField($field);
             if (is_array($dataValue)) {
                 foreach ($dataValue as $customFormId) {
                     $tempCForm = Kernel::getService('em')->find('RZ\\Roadiz\\Core\\Entities\\CustomForm', (int) $customFormId);
                     if ($tempCForm !== null) {
                         $hdlr->addCustomFormForField($tempCForm, $field);
                     }
                 }
             }
             break;
         case NodeTypeField::NODES_T:
             $hdlr = $nodeSource->getNode()->getHandler();
             $hdlr->cleanNodesFromField($field);
             if (is_array($dataValue)) {
                 foreach ($dataValue as $nodeId) {
                     $tempNode = Kernel::getService('em')->find('RZ\\Roadiz\\Core\\Entities\\Node', (int) $nodeId);
                     if ($tempNode !== null) {
                         $hdlr->addNodeForField($tempNode, $field);
                     }
                 }
             }
             break;
         case NodeTypeField::CHILDREN_T:
             break;
         default:
             $setter = $field->getSetterName();
             $nodeSource->{$setter}($dataValue);
             break;
     }
 }