Back to MenuRules class

Method buildLookup

protected void
buildLookup
(mixed $language = '*')
Method to build the lookup array
Parameters
  • string $language The language that the lookup should be built up for
Returns
  • void
Since
  • 3.4
Class: MenuRules
Project: Joomla

Method buildLookup - Source code

/**
 * Method to build the lookup array
 *
 * @param   string  $language  The language that the lookup should be built up for
 *
 * @return  void
 *
 * @since   3.4
 */
protected function buildLookup($language = '*')
{
    // Prepare the reverse lookup array.
    if (!isset($this->lookup[$language])) {
        $this->lookup[$language] = array();
        $component = ComponentHelper::getComponent('com_' . $this->router->getName());
        $views = $this->router->getViews();
        $attributes = array('component_id');
        $values = array((int) $component->id);
        $attributes[] = 'language';
        $values[] = array($language, '*');
        $items = $this->router->menu->getItems($attributes, $values);
        foreach ($items as $item) {
            if (isset($item->query['view'], $views[$item->query['view']])) {
                $view = $item->query['view'];
                $layout = '';
                if (isset($item->query['layout'])) {
                    $layout = ':' . $item->query['layout'];
                }
                if ($views[$view]->key) {
                    if (!isset($this->lookup[$language][$view . $layout])) {
                        $this->lookup[$language][$view . $layout] = array();
                    }
                    if (!isset($this->lookup[$language][$view])) {
                        $this->lookup[$language][$view] = array();
                    }
                    // If menuitem has no key set, we assume 0.
                    if (!isset($item->query[$views[$view]->key])) {
                        $item->query[$views[$view]->key] = 0;
                    }
                    /**
                     * Here it will become a bit tricky
                     * language != * can override existing entries
                     * language == * cannot override existing entries
                     */
                    if (!isset($this->lookup[$language][$view . $layout][$item->query[$views[$view]->key]]) || $item->language !== '*') {
                        $this->lookup[$language][$view . $layout][$item->query[$views[$view]->key]] = $item->id;
                        $this->lookup[$language][$view][$item->query[$views[$view]->key]] = $item->id;
                    }
                } else {
                    /**
                     * Here it will become a bit tricky
                     * language != * can override existing entries
                     * language == * cannot override existing entries
                     */
                    if (!isset($this->lookup[$language][$view . $layout]) || $item->language !== '*') {
                        $this->lookup[$language][$view . $layout] = $item->id;
                    }
                }
            }
        }
    }
}