item

Method to build an menu item.

@param array $item The menu item.
@param array $options Options.
@return string
503860
public function item($item = [], $options = [])
    {
        $html = '<li ' . ($item['active'] ? 'class="active"' : '') . '>' .
            $this->Html->link(__($item['title']), $item['url']) . '</li>';
        return $html;
    }
325896
public function __item($item = null)
    {
        $result['name'] = $this->getName();
        $result['content'] = '0';
        $result['active'] = is_null($item) ? true : $item['active'];
        $result['settings'] = Eresus_CMS::getLegacyKernel()->db->
            escape(is_null($item) ? encodeOptions($this->settings) : $item['settings']);
        $result['title'] = $this->title;
        $result['version'] = $this->version;
        $result['description'] = $this->description;
        return $result;
    }
371431
public static function ul( $items, $options = [] ) {
		$tag         = ArrayHelper::remove( $options, 'tag', 'ul');
		$encode      = ArrayHelper::remove( $options, 'encode', FALSE );
		$formatter   = ArrayHelper::remove( $options, 'item');
		$separator   = ArrayHelper::remove( $options, 'separator', "\n");
		$itemOptions = ArrayHelper::remove( $options, 'itemOptions', []);
		$classFor    = ArrayHelper::remove( $itemOptions, 'class_for', null );

		if ( empty( $items ) ) {
			return static::tag( $tag, '', $options );
		}
		$results = [];
		foreach ( $items as $i => $item ) {
			if ( $formatter !== NULL ) {
				$results[] = call_user_func( $formatter, $item, $i );
			} else {
				$_itemOptions = $itemOptions;
				if ( isset( $classFor ) && array_key_exists( $i, $classFor ) ) {
					static::addCssClass( $_itemOptions, $classFor[ $i ] );
				}
				$results[] = static::tag('li', $encode ? static::encode( $item ) : $item, $_itemOptions );
			}
		}

		return static::tag( $tag, $separator . join( $separator, $results ) . $separator, $options );
	}
1211317
protected function renderItem($item)
    {
        $item['label'] = $this->encodeLabels ? Html::encode($item['label']) : $item['label'];

        $options = ArrayHelper::getValue($item, 'options', $this->itemOptions);
        Html::addCssClass($options, 'section');

        if (isset($item['url'])) {
            $link = Html::a($item['label'], $item['url'], $options);
        } else {
            Html::addCssClass($options, 'active');
            $link = Html::tag('div', $item['label'], $options);
        }
        return $link;
    }
1000923
protected function createMenuItem(string $id, array $options): ?ItemInterface
    {
        return $this->factory->createItem($id, $options);
    }
761157
private function resolveRouteToLink(array $item)
    {
        $param = !empty($item['param']) ? $item['param'] : [];

        if (isset($item['add'])) {
            Deprecated::warn('Menu item property "add"', null, 'Use "#" under "param" instead.');

            $add = $item['add'];
            if (!empty($add) && $add[0] !== '?') {
                $add = '?' . $add;
            }

            parse_str(parse_url($add, PHP_URL_QUERY), $query);
            $param = array_merge($param, $query);
            $param['_fragment'] = parse_url($add, PHP_URL_FRAGMENT);
        }

        return $this->app['url_generator']->generate($item['route'], $param);
    }
290061
public function addItem($item){
		$itemO=$this->getItemToAdd($item);
		$this->addContent($itemO);
		return $itemO;
	}
659256
protected function renderItems($items, $options = [])
    {
        $lines = [];
        foreach ($items as $item) {
            if (is_string($item)) {
                $lines[] = $item;
                continue;
            }
            if (isset($item['visible']) && !$item['visible']) {
                continue;
            }
            if (!array_key_exists('label', $item)) {
                throw new InvalidConfigException("The 'label' option is required.");
            }
            $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
            $label = $encodeLabel ? Html::encode($item['label']) : $item['label'];
            $itemOptions = ArrayHelper::getValue($item, 'options', []);
            $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
            $linkOptions['tabindex'] = '-1';
            $url = array_key_exists('url', $item) ? $item['url'] : null;
            if (empty($item['items'])) {
                if ($url === null) {
                    $content = $label;
                    Html::addCssClass($itemOptions, ['widget' => 'dropdown-header']);
                } else {
                    $content = Html::a($label, $url, $linkOptions);
                }
            } else {
                $submenuOptions = $this->submenuOptions;
                if (isset($item['submenuOptions'])) {
                    $submenuOptions = array_merge($submenuOptions, $item['submenuOptions']);
                }
                $content = Html::a($label, $url === null ? '#' : $url, $linkOptions)
                    . $this->renderItems($item['items'], $submenuOptions);
                Html::addCssClass($itemOptions, ['widget' => 'dropdown-submenu']);
            }

            $lines[] = Html::tag('li', $content, $itemOptions);
        }

        return Html::tag('ul', implode("\n", $lines), $options);
    }
9354
public static function select( $items, $options = [] ) {
		$options['tag'] = 'select';
		$options['item'] = function ( $item, $index ) {
			$itemOptions = [];
			if ( is_array( $item ) ) {
				$label = $item['label'];
                $itemOptions['value'] = $item['value'];
				if ( ! empty( $item['options'] ) && ArrayHelper::isAssociative( $item['options'] ) ) {
                    $itemOptions = array_merge( $itemOptions, $item['options'] );
                }
			} else {
				$label = $item;
				$itemOptions['value'] = $item;
			}

			return static::tag('option', $label, $itemOptions );
		};

		return static::ul( $items, $options );
	}
225116
public static function menuLink($item)
    {
        $app = \JFactory::getApplication();
        $menu = $app->getMenu();
        $item = $menu->getItem($item);

        return \JRoute::_($item->link . '&Itemid=' . $item->id);
    }
1285630
protected function _renderChildren(ItemInterface $item, array $options)
    {
        if ($options['depth'] !== null) {
            $options['depth'] = $options['depth'] - 1;
        }

        if ($options['matchingDepth'] !== null &&
            $options['matchingDepth'] > 0
        ) {
            $options['matchingDepth'] = $options['matchingDepth'] - 1;
        }

        $children = [];
        foreach ($item->getChildren() as $child) {
            $children[] = $this->_renderItem($child, $options);
        }

        return $children;
    }
1189745
protected function _renderItem(ItemInterface $item, array $options)
    {
        if (!$item->isDisplayed()) {
            return '';
        }

        $level = $item->getLevel();

        $class = (array)$item->getAttribute('class');

        if ($this->_matcher->isCurrent($item)) {
            $class[] = $options['currentClass'];
        } elseif (isset($options['ancestorClass']) &&
            $this->_matcher->isAncestor($item, $options['matchingDepth'])
        ) {
            $class[] = $options['ancestorClass'];
        }

        if (isset($options['firstClass']) &&
            $item->actsLikeFirst()
        ) {
            $class[] = $options['firstClass'];
        }
        if (isset($options['lastClass']) &&
            $item->actsLikeLast()
        ) {
            $class[] = $options['lastClass'];
        }

        $hasChildren = $item->hasChildren();
        if ($hasChildren &&
            $options['depth'] !== 0
        ) {
            if ($options['branchClass'] !== null &&
                $item->getDisplayChildren()
            ) {
                $class[] = $options['branchClass'];
            }
        } elseif ($options['leafClass'] !== null) {
            $class[] = $options['leafClass'];
        }

        $attributes = $item->getAttributes();
        if (!empty($class)) {
            $attributes['class'] = implode(' ', $class);
        }

        $templater = $this->templater();

        $attributes = $this->_formatAttributes($attributes, $item);

        $templates = (array)$item->getExtra('templates');
        $defaultTemplates = (array)$item->getExtra('defaultTemplates');
        $newTemplates = $templates + $defaultTemplates;
        if ($newTemplates) {
            $templater->push();
            $templater->add($newTemplates);
        }

        $templateVars = (array)$item->getExtra('templateVars');
        $defaultTemplateVars = (array)$item->getExtra('defaultTemplateVars');
        $currentDefaultTemplateVars = (array)$options['defaultTemplateVars'];
        $templateVars =
            $templateVars +
            $defaultTemplateVars +
            $currentDefaultTemplateVars;
        if (empty($templateVars)) {
            $templateVars = null;
        }
        $options['templateVars'] = $templateVars;

        $link = $this->_renderLink($item, $options);

        if ($hasChildren) {
            $nestedClass = (array)$item->getChildrenAttribute('class');
            if ($options['menuLevelClass'] !== null) {
                $nestedClass[] = $options['menuLevelClass'] . $level;
            }
            if ($options['nestedMenuClass'] !== null) {
                $nestedClass[] = $options['nestedMenuClass'];
            }
            $nestedAttributes = $item->getChildrenAttributes();
            $nestedAttributes['class'] = implode(' ', $nestedClass);
            $options['attributes'] = $nestedAttributes;

            $options['childrenTemplates'] = null;
            if ($newTemplates) {
                // item defines new templates that must be ignored by the children
                $options['childrenTemplates'] = $options['defaultTemplates'];
            }
            if ($defaultTemplates) {
                // item defines default templates that must be used by the children
                $options['childrenTemplates'] = $defaultTemplates;
            }

            if ($defaultTemplateVars) {
                // item defines default template vars that must be used by the children
                $options['defaultTemplateVars'] =
                    $defaultTemplateVars +
                    $currentDefaultTemplateVars;
            }

            $nested = $this->_renderNested($item, $options);
        } else {
            $nested = '';
        }

        $rendered = (string)$templater->format('item', [
            'attrs' => $attributes,
            'templateVars' => $templateVars,
            'link' => $link,
            'nest' => $nested
        ]);

        if ($newTemplates) {
            $templater->pop();
        }

        return $rendered;
    }
937698
public function line(array $item)
	{
		$val = print_r($item['var'], true);
		$val = preg_replace('/\[(.+?)\] =>/i', '<code class="ky">[$1]</code> <code class="op">=></code>', $val);
		return '<pre>' . $val . '</pre>';
	}
12294
private function buildSubjectItem($menu, $item)
    {
        if (! empty($item->subject_type) && ! is_null($item->subject)) {
            return $menu->add($item->name, ['url' => $item->subject->getRouteForMenuItem()]);
        }

        return false;
    }
740132
public function getChildMenuItems(MenuItem $item): string
    {
        $results = '';

        foreach ($item->getChilds() as $child) {
            if ($child->isHidden()) {
                continue;
            }

            if ($child->hasChilds()) {
                $results .= $this->getMultiLevelDropdownWrapper($child);
            } elseif ($child->isHeader()) {
                $results .= $this->getHeaderWrapper($child);
            } elseif ($child->isDivider()) {
                $results .= $this->getDividerWrapper();
            } else {
                $results .= $this->getMenuWithoutDropdownWrapper($child);
            }
        }

        return $results;
    }
735810
protected function addItem($item, $options = [])
    {
        $nextTo = array_get($options, 'next_to');
        $position = false;
        foreach ($this->items as $index => $m) {
            if ($m['id'] == $nextTo) {
                $position = $index;
            }
        }

        $newMenu = [
            'item'      => $item,
            'before'    => array_get($options, 'before', ''),
            'after'     => array_get($options, 'after', ''),
            'url_def'   => array_get($options, 'url_def'),
            'is_active' => array_get($options, 'is_active'),
            'id'        => array_get($options, 'id'),
        ];

        if ($position !== false) {
            array_splice($this->items, $position + 1, 0, [$newMenu]);
        } else {
            $this->items[] = $newMenu;
        }

        return $this;
    }
500953
public function getWidgetItem(array $item) {
        $entity = new ItemWidget();

        $entity->setName($this->getItemName($item));
        $entity->setLink($this->browser->getHost().$item['url']);
        $entity->setCover($this->browser->getHost().$item['image']['original']);

        $catalog_item = $this->getCatalogItem($item);
        if ($catalog_item instanceof Item) {
            $entity->setItem($catalog_item);
        } elseif ($this->filler instanceof Filler) {
            $entity->setLinkForFill($this->filler->getLinkForFill($entity->getLink()));
        }

        return $entity;
    }