/** * Renders a widget's item. * @param string|array $item the item to render. * @return string the rendering result. * @throws InvalidConfigException */ public function renderItem($item) { if (is_string($item)) { return $item; } 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', []); $items = ArrayHelper::getValue($item, 'items'); $url = ArrayHelper::getValue($item, 'url', '#'); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []); if (isset($item['active'])) { $active = ArrayHelper::remove($item, 'active', false); } else { $active = $this->isItemActive($item); } if (empty($items)) { $items = ''; } else { $toggleTarget = 'dropdown_' . md5(uniqid()); $linkOptions['data-activates'] = $toggleTarget; Html::addCssClass($options, ['widget' => 'dropdown']); Html::addCssClass($linkOptions, ['widget' => 'dropdown-button']); if ($this->dropDownCaret !== '') { $label .= ' ' . $this->dropDownCaret; } if (is_array($items)) { if ($this->activateItems) { $items = $this->isChildActive($items, $active); } $items = $this->renderDropdown($items, $item, $toggleTarget); } } if ($this->activateItems && $active) { Html::addCssClass($options, 'active'); } return Html::tag('li', Html::a($label, $url, $linkOptions) . $items, $options); }
/** * Executes the widget. * @return string the result of widget execution to be outputted. * @uses [[renderIcon]] */ public function run() { if ($this->label !== false) { $label = $this->encodeLabel ? Html::encode($this->label) : $this->label; } else { $label = ''; } $content = $this->renderIcon() . $label; return $this->tagName === 'button' ? Html::button($content, $this->options) : Html::tag($this->tagName, $content, $this->options); }
/** * Renders the close button. * @see closeButton * @return null|string the rendered result. */ protected function renderCloseButton() { if (($closeButton = $this->closeButton) !== false) { $tag = ArrayHelper::remove($closeButton, 'tag', 'button'); $label = ArrayHelper::remove($closeButton, 'label', '×'); Html::addCssClass($closeButton, ['close' => 'modal-close']); if ($tag === 'button' && !isset($closeButton['type'])) { $closeButton['type'] = 'button'; } return Html::tag($tag, $label, $closeButton); } else { return null; } }
/** * Render the switch button checkbox. * @return string * @uses [yii\helper\BaseHtml::checkbox()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#checkbox()-detail) */ protected function renderSwitch() { $value = ArrayHelper::getValue($this->inputOptions, 'value', null); if ($this->hasModel()) { $attributeValue = Html::getAttributeValue($this->model, $this->attribute); $this->checked = "{$value}" === "{$attributeValue}"; } $name = ArrayHelper::remove($this->inputOptions, 'name', null); return implode("\n", [Html::beginTag('label'), $this->renderLabel('off'), Html::checkbox($name, $this->checked, $this->inputOptions), Html::tag('span', '', ['class' => 'lever']), $this->renderLabel('on'), Html::endTag('label')]); }
/** * Renders a list representing the single button items. * @return string * @throws InvalidConfigException */ protected function renderItems() { $elements = []; $items = $this->items; foreach ($items as $item) { if (isset($item['visible']) && !$item['visible']) { continue; } if (is_string($item)) { $elements[] = $item; 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', []); $url = array_key_exists('url', $item) ? $item['url'] : null; if ($url === null) { $content = $label; } else { $content = Html::a($label, $url, $linkOptions); } $elements[] = Html::tag('li', $content, $itemOptions); } return Html::tag('ul', implode("\n", $elements), $this->itemsContainerOptions); }
/** * Executes the widget. * @return string the result of widget execution to be outputted. */ public function run() { $html[] = Html::beginTag('div', $this->options); $html[] = Html::tag('div', null, $this->progressOptions); $html[] = Html::endTag('div'); return implode("\n", $html); }
/** * Renders menu items. * * @param array $items the menu items to be rendered * @param array $options the container HTML attributes * @return string the rendering result. * @throws InvalidConfigException if the label option is not specified in one of the items. * @used-by [[run()]] */ protected function renderItems($items, $options = []) { $lines = []; foreach ($items as $item) { if (isset($item['visible']) && !$item['visible']) { continue; } if (is_string($item)) { $lines[] = $item; 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); }
/** * Executes the widget. * @return string the result of widget execution to be outputted. */ public function run() { $tag = ArrayHelper::remove($this->options, 'tag', 'i'); return Html::tag($tag, $this->name, $this->options); }