/** * 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. */ protected function renderItems($items, $options = []) { $lines = []; foreach ($items as $i => $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', []); $url = array_key_exists('url', $item) ? $item['url'] : null; if (empty($item['items'])) { if ($url === null) { $content = $label; } else { $content = Html::a($label, $url, $linkOptions); } } else { $submenuOptions = $options; unset($submenuOptions['id']); $content = Html::a($label, $url === null ? '#' : $url, $linkOptions) . $this->renderItems($item['items'], $submenuOptions); Html::addCssClass($itemOptions, 'dropdown-submenu'); } $lines[] = Html::tag('li', $content, $itemOptions); } return Html::tag('ul', implode("\n", $lines), $options); }
/** * Initializes the widget. * If you override this method, make sure you call the parent implementation first. */ public function init() { parent::init(); $this->clientOptions = false; if ($this->defaultClass) { Html::addCssClass($this->options, $this->defaultClass); } }
public function run() { if (!isset($this->clientOptions['container'])) { $this->clientOptions['container'] = 'body'; } $this->registerPlugin('pickadate'); Html::addCssClass($this->options, 'datepicker'); if ($this->hasModel()) { $this->options['data-value'] = isset($this->value) ? $this->value : Html::getAttributeValue($this->model, $this->attribute); return Html::activeInput('date', $this->model, $this->attribute, $this->options); } else { $this->options['data-value'] = $this->value; return Html::input('date', $this->name, $this->value, $this->options); } }
/** * Initializes the widget options. * This method sets the default values for various options. */ protected function initOptions() { if ($this->modalType !== null) { Html::addCssClass($this->options, $this->modalType); } Html::addCssClass($this->options, 'modal'); if ($this->clientOptions !== false) { $this->clientOptions = array_merge(['show' => false], $this->clientOptions); } if ($this->closeButton !== false) { Html::addCssClass($this->closeButton, 'modal-close'); } if ($this->toggleButton !== false) { Html::addCssClass($this->toggleButton, 'modal-trigger'); if (!isset($this->toggleButton['data-target']) && !isset($this->toggleButton['href'])) { $this->toggleButton['data-target'] = $this->options['id']; } } }
protected function renderCardContent($data) { foreach ($data as $content) { if (isset($content['activator'])) { Html::addCssClass($content['options'], 'card-title'); Html::addCssClass($content['options'], 'activator'); } $contents[] = Html::tag(isset($content['tag']) ? $content['tag'] : 'span', $content['body'], isset($content['options']) ? $content['options'] : []); } return implode("\n", $contents); }