/** * Loads the widgets of the node for the provided regions * @param ride\library\cms\widget\WidgetModel * @param array $regions Array with the name of the region as key and a * instance of Region as value * @return null */ public function loadWidgets(WidgetModel $widgetModel, array $regions) { $this->regions = array(); $this->widgets = array(); foreach ($regions as $region => $null) { $this->widgets[$region] = array(); $this->regions[$region] = $this->node->getSections($region); foreach ($this->regions[$region] as $section => $layout) { $this->widgets[$region][$section] = $this->node->getWidgets($region, $section); foreach ($this->widgets[$region][$section] as $block => $widgets) { foreach ($widgets as $widgetId => $widget) { $widget = $widgetModel->getWidget($widget); if ($widget) { $this->widgets[$region][$section][$block][$widgetId] = clone $widget; } else { unset($this->widgets[$region][$section][$block][$widgetId]); } } if (!$this->widgets[$region][$section][$block]) { unset($this->widgets[$region][$section][$block]); } } if (!$this->widgets[$region][$section]) { unset($this->widgets[$region][$section]); unset($this->regions[$region][$section]); } } if (!$this->widgets[$region]) { unset($this->widgets[$region]); unset($this->regions[$region]); } } }
/** * Processes the widgets of a section to make them ready for usage * @param \ride\library\cms\node\Node $node Instance of the node * @param string $region Name of the region * @param string $section Name of the section * @param array $availableWidgets Array with the id of a widget instance as * key and the dependency id as value * @param array $widgets Array for the resulting widgets. The key will be * the id of the block, the value an array with the widget id as key and the * widget instance as value * @param array $inheritedWidgets Array with structure of the $widgets var * indicating which widgets are inherited, value in the block array is a * widget id and not a widget instance * @return null */ protected function processSectionWidgets(Node $node, $locale, $region, $section, array $availableWidgets, array &$widgets, array &$inheritedWidgets) { $inheritedSectionWidgets = $node->getInheritedWidgets($region, $section); $sectionWidgets = $node->getWidgets($region, $section); foreach ($sectionWidgets as $block => $blockWidgets) { $widgets[$block] = array(); $inheritedWidgets[$block] = array(); foreach ($blockWidgets as $widgetId => $widget) { if (!$widget || !isset($availableWidgets[$widget])) { continue; } $widget = clone $availableWidgets[$widget]; $widget->setIdentifier($widgetId); $widget->setProperties($node->getWidgetProperties($widgetId)); $widget->setLocale($locale); if ($widget instanceof AbstractController) { $widget->setConfig($this->config); $widget->setDependencyInjector($this->dependencyInjector); } $widgets[$block][$widgetId] = $widget; if (isset($inheritedSectionWidgets[$block][$widgetId])) { $inheritedWidgets[$block][$widgetId] = $widgetId; } } } }
/** * Gets all the extra widget URL's * @param array $result Result to add URL's to * @param \ride\library\cms\node\Node $node Node to process * @param string $locale * @param string $nodeUrl * @return array */ protected function getWidgetUrls(array $result, Node $node, $locale, $nodeUrl) { $theme = $this->cms->getTheme($node->getTheme()); $regions = $theme->getRegions(); foreach ($regions as $region => $null) { $sections = $node->getSections($region); foreach ($sections as $section => $layout) { $widgets = $node->getWidgets($region, $section); foreach ($widgets as $block => $widgets) { foreach ($widgets as $widgetId => $widget) { $widget = $this->cms->getWidget($widget); if (!$widget) { continue; } $widget = clone $widget; $widget->setIdentifier($widgetId); $widget->setRegion($region); $widget->setSection($section); $widget->setBlock($block); $widget->setProperties($node->getWidgetProperties($widgetId)); $widget->setLocale($locale); $routes = $widget->getRoutes(); if (!$routes) { continue; } foreach ($routes as $route) { $path = $route->getPath(); $pathTokens = $route->getPathTokens(); foreach ($pathTokens as $token) { if (substr($token, 0, 1) == '%' && substr($token, -1) == '%') { $path = str_replace($token, '*', $path); } } $result[] = $nodeUrl . $path; } } } } } return $result; }