生成下拉节点(有子菜单的项)

@param string|array $item
the item to render.
@param bool $active
@return string the rendering result.
@throws InvalidConfigException
191862
public function renderDropDownItem($item, &$active = false)
    {
        if (is_string($item)) {
            return $item;
        }
        if (!isset($item['label'])) {
            throw new InvalidConfigException("The 'label' option is required.");
        }
        $subItems = ArrayHelper::getValue($item, 'items');

        $options = ArrayHelper::getValue($item, 'options', []);
        $active = $this->isItemActive($item);

        $item['linkOptions'] = ['class' => 'dropdown-toggle'];
        if (is_array($subItems)) {
            if ($this->activateItems) {
                $subItems = $this->isChildActive($subItems, $active);
            }
            $subItems = $this->renderSubItems($subItems, $active);
        }
        if ($this->activateItems && $active) {
            Html::addCssClass($options, 'active open');
        }
        $linkHtml = $this->renderItemLink($item);


        return Html::tag('li', $linkHtml . $subItems, $options);
    }
1036352
protected function _renderChildren($item, $level)
    {
        if (!$this->_hasChildren($item)) {
            return '';
        }

        $subnavItems = $this->renderNested($item['children'], $level);
        if ($subnavItems === '') {
            return '';
        }

        $templater = $this->templater();

        $htmlAttributes = [
            'class' => $this->_buildSubnavClasses($item, $level)
        ];

        return $this->formatTemplate('subnav', [
            'attrs' => $templater->formatAttributes($htmlAttributes),
            'items' => $subnavItems
        ]);
    }
732478
public static function createMenuItem(array $item): MenuItemInterface
    {
        $menuItem = static::_getMenuItemObject($item);
        foreach ($item as $key => $value) {
            if ($key == 'children') {
                foreach ($value as $k => $v) {
                    $childItem = static::createMenuItem($v);
                    $menuItem->addMenuItem($childItem);
                }
            } elseif ($key == 'attributes') {
                foreach ($value as $k => $v) {
                    $menuItem->addAttribute($k, $v);
                }
            } elseif ($key == 'viewElement') {
                call_user_func_array([$menuItem, 'setViewElement'], $value);
            } else {
                $method = 'set' . ucfirst(Inflector::camelize($key));
                if (method_exists($menuItem, $method)) {
                    $menuItem->$method($value);
                }
            }
        }

        return $menuItem;
    }
943566
public static function prepareItems($items)
    {
        if (!is_array($items)) {
            throw new InvalidConfigException(Yii::t('app', 'List items should be an array.'));
        }
        if (isset($items['class']) && isset($items['method'])) {
            return call_user_func([$items['class'], $items['method']]);
        } else {
            return $items;
        }
    }
1173860
protected function renderAsItems($items) {
    $lines = [];
    foreach ($items as $i => $item) {
      if (isset($item['visible']) && !$item['visible']) {
        unset($items[$i]);
        continue;
      }
      if (is_string($item)) {
        $lines[] = $item;
        continue;
      }
      if (!isset($item['label'])) {
        throw new InvalidConfigException("The 'label' option is required.");
      }

      $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
      $label = $encodeLabel ? Html::encode($item['label']) : $item['label'];
      $options = ArrayHelper::getValue($item, 'options', []);
      $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
      $content = Html::a($label, ArrayHelper::getValue($item, 'url', '#'), $linkOptions);
      $lines[] = Html::tag('li', $content, $options);
    }

    return implode("\n", $lines);
  }
847906
public function add ($item) {
        if ($this->name === null) {
            throw new InvalidConfigException(get_class ($this) . " requires a name!");
        }
        if (!$this->getConnection ()->getClient ()->rpush ($this->name , $item)) {
            return false;
        }
        $this->_data = null;
        $this->_count = null;
        return true;
    }
305351
public function item($item = [], $options = [])
    {
        $html = '<li style="display: inline; list-style-type: none; padding-right: 20px;">';
        $html .= (key_exists('active', $item) && $item['active'] ? '<b>' : '');
        $html .= $this->Html->link(__($item['title']), $item['url']);
        $html .= (key_exists('active', $item) ? '</b>' : '');
        $html .= '</li>';
        return $html;
    }
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;
    }
1147318
protected function renderItems()
    {
        $items = [];
        foreach ($this->items as $item) {
            if (!array_key_exists('header', $item)) {
                throw new InvalidConfigException("The 'header' option is required.");
            }
            if (!array_key_exists('content', $item)) {
                throw new InvalidConfigException("The 'content' option is required.");
            }
            $headerOptions = array_merge($this->headerOptions, ArrayHelper::getValue($item, 'headerOptions', []));
            $headerTag = ArrayHelper::remove($headerOptions, 'tag', 'h3');
            $items[] = Html::tag($headerTag, $item['header'], $headerOptions);
            $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', []));
            $tag = ArrayHelper::remove($options, 'tag', 'div');
            $items[] = Html::tag($tag, $item['content'], $options);
        }

        return implode("\n", $items);
    }
52419
public function formatItem($item, $format = 'json')
    {
        $formatted = null;

        switch ($format) {
            case 'json':
                // serialize properties with null values
                $context = new SerializationContext();
                $context->setSerializeNull(true);
                $context->enableMaxDepthChecks(true);
                $formatted = $this->getSerializer()->serialize($item, 'json', $context);
                break;
            case 'jsonp':
                $callback = $this->getRequest()->query->get('jsonp.callback', 'JSONP.callback');

                // validate against XSS
                $validator = new \JsonpCallbackValidator();
                if (!$validator->validate($callback)) {
                    throw new BadRequestHttpException('Invalid JSONP callback value');
                }

                $context = new SerializationContext();
                $context->setSerializeNull(true);
                $json = $this->getSerializer()->serialize($item, 'json');

                $formatted = sprintf('/**/%s(%s)', $callback, $json);
                break;
            default:
                // any other format is not supported
                throw new \InvalidArgumentException(sprintf('Format not supported: %s', $format));
        }

        return $formatted;
    }
1133283
public function renderMenuPart($items)
    {
        $items = $this->normalizeItems($items, $hasActiveChild);

        $lines = '';
        foreach ($items as $i => $item) {
            Html::addCssClass($item['options'], 'item');
            if ($item['active']) {
                Html::addCssClass($item['options'], 'active');
            }

            if (isset($item['items'])) {
                Html::addCssClass($item['options'], 'ui simple dropdown');
                $item['label'] =
                    $item['label'] .
                    Elements::icon('dropdown') .
                    Html::tag('div', $this->renderMenuPart($item['items']), ['class' => 'menu']);

                $menu = $this->renderItem($item);
            } else {
                $menu = $this->renderItem($item);
            }
            $lines .= $menu;
        }
        return $lines;
    }
197198
public static function build($array, $elements = [], $currentItems = [], $activeClass = 'active', $startLevel = 0, $numLevels = 2, $caret = false, $linkDDExtras = false) {
        if(is_array($elements) && !empty($elements)){Link::$linkDefaults = $elements;}
        if($caret !== false && is_string($caret)){Link::$caretElement = $caret;}
        if($linkDDExtras !== false && is_string($linkDDExtras)){Link::$dropdownLinkExtras = $linkDDExtras;}
        return self::createMenuLevel($array, 0, $elements, $currentItems, $activeClass, $startLevel, $numLevels);
    }
824306
protected function quoteItem(
        $item,
        array $settings,
        /*# bool */ $rawMode = false
    )/*# : string */ {
        // is an object
        if (is_object($item)) {
            return $this->quoteObject($item, $settings);
        }

        // is a string, quote with prefix and suffix
        return $rawMode ? $item : $this->quote($item, $settings);
    }
546902
protected function normalizeItems($items, &$active)
    {
        foreach ($items as $i => $item) {
            if (isset($item['visible']) && !$item['visible']) {
                unset($items[$i]);
                continue;
            }
            if (!isset($item['label'])) {
                $item['label'] = '';
            }
            $encodeLabel = $item['encode'] ?? $this->encodeLabels;
            $items[$i]['label'] = $encodeLabel ? Html::encode($item['label']) : $item['label'];
            $hasActiveChild = false;
            if (isset($item['items'])) {
                $items[$i]['items'] = $this->normalizeItems($item['items'], $hasActiveChild);
                if (empty($items[$i]['items']) && $this->hideEmptyItems) {
                    unset($items[$i]['items']);
                    if (!isset($item['url'])) {
                        unset($items[$i]);
                        continue;
                    }
                }
            }
            if (!isset($item['active'])) {
                if ($this->activateParents && $hasActiveChild || $this->activateItems && $this->isItemActive($item)) {
                    $active = $items[$i]['active'] = true;
                } else {
                    $items[$i]['active'] = false;
                }
            } elseif ($item['active'] instanceof Closure) {
                $active = $items[$i]['active'] = call_user_func($item['active'], $item, $hasActiveChild, $this->isItemActive($item), $this);
            } elseif ($item['active']) {
                $active = true;
            }
        }

        return array_values($items);
    }
785646
public function getAdminObjectTargetUrl($item)
    {
        if ($item->getTargetId()) {
            /** @var AbstractAdmin $admin */
            $admin = $this->getContainer()->get('sonata.admin.pool')->getAdminByClass($item->getClass());

            return $admin->generateObjectUrl('edit', $admin->getObject($item->getTargetId()));
        }

        return '';
    }
857729
protected static function createItem(array $item)
    {
        $microformatItem = ['type' => self::createTypes($item['type']), 'lang' => null];
        self::processProperties($item, $microformatItem);
        self::processValue($item, $microformatItem);
        self::processChildren($item, $microformatItem);

        return (object)$microformatItem;
    }
1329178
public function render($items, $activeClass = 'active')
    {
        $out = '';
        foreach ($items as $item) {
            $class = '';
            if (isset($item['active']) && $item['active'] === true) {
                $class = ' class="' . $activeClass . '"';
            }
            $out .= '<li' . $class . '>';
            $out .= $this->Guardian->protectedLink($item['name'], $item['url']);
            $out .= '</li>';
        }
        return $out;
    }