/** * 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]); } } }
/** * 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; }