/** * This method exists because the service container needs to be set before * the page's functionality gets loaded. */ public function initialize() { $url = new Url($this->getKernel()); new TwigTemplate(); new Navigation($this->getKernel()); new Header($this->getKernel()); $this->action = new Action($this->getKernel()); $this->action->setModule($url->getModule()); $this->action->setAction($url->getAction()); }
/** * Display, this wil output the template to the browser * If no template is specified we build the path form the current module and action * * @param string $template The template to use, if not provided it will be based on the action. */ public function display($template = null) { // parse header $this->header->parse(); /* * If no template is specified, we have to build the path ourself. The default template is * based on the name of the current action */ if ($template === null) { $template = $this->getBackendModulePath() . '/Layout/Templates/' . $this->URL->getAction() . '.tpl'; } $this->content = $this->tpl->getContent($template); }
/** * Try to determine the selected state * * @param array $value The value. * @param int $key The key. * @param array $keys The previous marked keys. * @return mixed */ private function compareURL(array $value, $key, $keys = array()) { // create active url $activeURL = $this->URL->getModule() . '/' . $this->URL->getAction(); // we use the lowercased versions in the url $activeURL = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $activeURL)); // add current key $keys[] = $key; // sub action? if (isset($value['selected_for']) && in_array($activeURL, (array) $value['selected_for'])) { return $keys; } // if the URL is available and same as the active one we have what we need. if (isset($value['url']) && $value['url'] == $activeURL) { if (isset($value['children'])) { // loop the children foreach ($value['children'] as $key => $value) { // recursive here... $subKeys = $this->compareURL($value, $key, $keys); // wrap it up if (!empty($subKeys)) { return $subKeys; } } } // fallback return $keys; } // any children if (isset($value['children'])) { // loop the children foreach ($value['children'] as $key => $value) { // recursive here... $subKeys = $this->compareURL($value, $key, $keys); // wrap it up if (!empty($subKeys)) { return $subKeys; } } } }