/** * @static * * @param Node $pNode * @param array $pChildren */ function installNodes(Node $pNode, $pChildren) { /* * 0: type * 1: Title * 2: layout * 3: url * 4: link target * 5: contents * 6: children * 7: visible */ foreach ($pChildren as $Node) { $oNode = new Node(); $oNode->setDomainId($pNode->getDomainId()); $oNode->setType($Node[0]); $oNode->setTitle($Node[1]); $oNode->setLayout($Node[2]); $oNode->setUrn($Node[3]); $oNode->insertAsLastChildOf($pNode); if ($Node[4]) { $oNode->setLink($Node[4]); } if (isset($Node[7])) { $oNode->setVisible($Node[7]); } else { $oNode->setVisible(1); } $oNode->save(); if (isset($Node[5])) { $this->installContents($oNode, $Node[5]); } if (isset($Node[6])) { $this->installNodes($oNode, $Node[6]); } } }
public function registerPluginRoutes(Node $page) { $domain = $this->pageStack->getDomain($page->getDomainId()); $this->stopwatch->start('Register Plugin Routes'); //add all router to current router and fire sub-request $cacheKey = 'core/node/plugins-' . $page->getId(); $plugins = $this->cacher->getDistributedCache($cacheKey); if (null === $plugins) { $plugins = ContentQuery::create()->filterByNodeId($page->getId())->filterByType('plugin')->find(); $this->cacher->setDistributedCache($cacheKey, serialize($plugins)); } else { $plugins = unserialize($plugins); } /** @var $plugins Content[] */ foreach ($plugins as $plugin) { if (!$plugin->getContent()) { continue; } $data = json_decode($plugin->getContent(), true); if (!$data) { $this->logger->alert(sprintf('On page `%s` [%d] is a invalid plugin `%d`.', $page->getTitle(), $page->getId(), $plugin->getId())); continue; } $bundleName = isset($data['module']) ? $data['module'] : @$data['bundle']; $config = $this->jarves->getConfig($bundleName); if (!$config) { $this->logger->alert(sprintf('Bundle `%s` for plugin `%s` on page `%s` [%d] does not not exist.', $bundleName, @$data['plugin'], $page->getTitle(), $page->getId())); continue; } $pluginDefinition = $config->getPlugin(@$data['plugin']); if (!$pluginDefinition) { $this->logger->alert(sprintf('In bundle `%s` the plugin `%s` on page `%s` [%d] does not not exist.', $bundleName, @$data['plugin'], $page->getTitle(), $page->getId())); continue; } if ($pluginRoutes = $pluginDefinition->getRoutes()) { foreach ($pluginRoutes as $idx => $route) { $controller = $pluginDefinition->getController(); $defaults = array('_controller' => $route->getController() ?: $controller, '_jarves_is_plugin' => true, '_content' => $plugin, '_title' => sprintf('%s: %s', $bundleName, $pluginDefinition->getLabel()), 'options' => isset($data['options']) && is_array($data['options']) ? $data['options'] : [], 'jarvesFrontend' => true, 'nodeId' => $page->getId()); if ($route->getDefaults()) { $defaults = array_merge($defaults, $route->getArrayDefaults()); } $url = $this->pageStack->getRouteUrl($page->getId()); $this->routes->add('jarves_frontend_plugin_' . ($route->getId() ?: $plugin->getId()) . '_' . $idx, new SyRoute($url . '/' . $route->getPattern(), $defaults, $route->getArrayRequirements() ?: array(), [], '', [], $route->getMethods() ?: [])); } } } $this->stopwatch->stop('Register Plugin Routes'); }