/** * Executes the widget. * @return string the result of widget execution to be outputted. */ public function run() { $this->registerAssets(); Html::addCssClass($this->options, 'clockpicker'); if ($this->hasModel()) { $this->options['data-value'] = isset($this->value) ? $this->value : Html::getAttributeValue($this->model, $this->attribute); return Html::activeInput('time', $this->model, $this->attribute, $this->options); } else { $this->options['data-value'] = $this->value; return Html::input('time', $this->name, $this->value, $this->options); } }
/** * Initializes the default button rendering callbacks. * This method uses [[Icon|Icon]] to display iconic buttons. */ protected function initDefaultButtons() { if (!isset($this->buttons['view'])) { $this->buttons['view'] = function ($url, $model, $key) { $options = array_merge(['title' => Yii::t('yii', 'View'), 'aria-label' => Yii::t('yii', 'View'), 'data-pjax' => '0'], $this->buttonOptions); return Html::a(Icon::widget(['name' => 'visibility']), $url, $options); }; } if (!isset($this->buttons['update'])) { $this->buttons['update'] = function ($url, $model, $key) { $options = array_merge(['title' => Yii::t('yii', 'Update'), 'aria-label' => Yii::t('yii', 'Update'), 'data-pjax' => '0'], $this->buttonOptions); return Html::a(Icon::widget(['name' => 'edit']), $url, $options); }; } if (!isset($this->buttons['delete'])) { $this->buttons['delete'] = function ($url, $model, $key) { $options = array_merge(['title' => Yii::t('yii', 'Delete'), 'aria-label' => Yii::t('yii', 'Delete'), 'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'), 'data-method' => 'post', 'data-pjax' => '0'], $this->buttonOptions); return Html::a(Icon::widget(['name' => 'delete']), $url, $options); }; } }
</head> <body> <?php $this->beginBody(); ?> <header class="page-header"> <?php NavBar::begin(['brandLabel' => 'My Company', 'brandUrl' => Yii::$app->homeUrl, 'fixed' => true, 'wrapperOptions' => ['class' => 'container']]); $menuItems = [['label' => 'Home', 'url' => ['/site/index']], ['label' => 'About', 'url' => ['/site/about']], ['label' => 'Contact', 'url' => ['/site/contact']]]; if (Yii::$app->user->isGuest) { $menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']]; $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']]; } else { $menuItems[] = '<li>' . Html::beginForm(['/site/logout'], 'post') . Html::submitButton('Logout (' . Yii::$app->user->identity->username . ')', ['class' => 'btn btn-flat']) . Html::endForm() . '</li>'; } echo Nav::widget(['options' => ['class' => 'right'], 'items' => $menuItems]); NavBar::end(); ?> </header> <main class="content"> <div class="container"> <?php echo Breadcrumbs::widget(['links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : []]); ?> <?php echo Alert::widget(); ?>
/** * Check to see if a child item is active optionally activating the parent. * @param array $items @see items * @param boolean $active should the parent be active too * @return array @see items */ protected function isChildActive($items, &$active) { foreach ($items as $i => $child) { if (ArrayHelper::remove($items[$i], 'active', false) || $this->isItemActive($child)) { Html::addCssClass($items[$i]['options'], 'active'); if ($this->activateParents) { $active = true; } } } return $items; }
/** * Renders a textarea. * @param array $options * @return ActiveField */ public function textarea($options = []) { Html::addCssClass($options, ['textarea' => 'materialize-textarea']); return parent::textarea($options); }
/** * Set inital default options. */ protected function initDefaults() { switch ($this->modalType) { case self::TYPE_FIXED_FOOTER: Html::addCssClass($this->options, ['modalType' => 'modal-fixed-footer']); break; case self::TYPE_BOTTOM_SHEET: Html::addCssClass($this->options, ['modalType' => 'bottom-sheet']); break; default: break; } Html::addCssClass($this->options, ['widget' => 'modal']); if ($this->closeButton !== false) { $this->closeButton = ArrayHelper::merge(['class' => 'modal-close'], $this->closeButton); } if ($this->toggleButton !== false) { $this->toggleButton = ArrayHelper::merge(['class' => 'modal-trigger btn'], $this->toggleButton); } if ($this->clientOptions !== false) { $this->clientOptions = ArrayHelper::merge(['show' => false], $this->clientOptions); } }
/** * Executes the widget. * @return string the result of widget execution to be outputted. * @uses [[Icon]] */ public function run() { $tag = ArrayHelper::remove($this->options, 'tag', 'div'); $html = Html::beginTag($tag, $this->options); if ($this->imageOptions) { $src = ArrayHelper::remove($this->imageOptions, 'src', ''); $html .= Html::img($src, $this->imageOptions); } $html .= $this->encodeContent ? Html::encode($this->content) : $this->content; if ($this->renderIcon) { $html .= Icon::widget(['name' => ArrayHelper::getValue($this->icon, 'name', null), 'position' => ArrayHelper::getValue($this->icon, 'position', ''), 'options' => ArrayHelper::getValue($this->icon, 'options', [])]); } $html .= Html::endTag($tag); return $html; }
/** * 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); }
/** * 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); }
/** * Renders the HTML markup for the on/off label. * * This method also renders the corresponding icons, if set. * * @param string $state the state to used. Use "off" or "on". * @return string the rendered label. * @uses [[Icon|Icon]] */ protected function renderLabel($state) { $icon = $this->renderIcon($state); $encodeProperty = "encode" . ucfirst($state) . "Text"; $textProperty = "{$state}Text"; $label = $this->{$encodeProperty} ? Html::encode($this->{$textProperty}) : $this->{$textProperty}; $label .= $icon; $html = []; $html[] = Html::beginTag('span', ['class' => "{$state}Label"]); $html[] = $label; $html[] = Html::endTag('span'); return implode("\n", $html); }
/** * 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); }
/** * Renders a single flash message. * @param string $message the content of the message * @param array $options the HTML attributes for the container tag * @return string */ private function renderHtml($message, $options = []) { $html = Html::beginTag('div', $options); $html .= '<div class="card-panel">'; $html .= $message; $html .= '</div>'; $html .= Html::endTag('div'); return $html; }
/** * 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. * @uses [[renderSpinner()]] */ public function run() { $html[] = Html::beginTag('div', $this->options); if ($this->flashColors !== false) { foreach ($this->colors as $color) { Html::addCssClass($this->spinnerOptions, ['color' => 'spinner-' . $color]); $html[] = Html::beginTag('div', $this->spinnerOptions); $html[] = $this->renderSpinner(); $html[] = Html::endTag('div'); Html::removeCssClass($this->spinnerOptions, ['color' => 'spinner-' . $color]); } } else { $html[] = Html::beginTag('div', $this->spinnerOptions); $html[] = $this->renderSpinner(); $html[] = Html::endTag('div'); } $html[] = Html::endTag('div'); return implode("\n", $html); }
/** * Renders a single breadcrumb item. * @param array $link the link to be rendered. It must contain the "label" element. The "url" element is optional. * @param string $template the template to be used to rendered the link. The token "{link}" will be replaced by the link. * @return string the rendering result * @throws InvalidConfigException if `$link` does not have "label" element. */ protected function renderItem($link, $template) { $encodeLabel = ArrayHelper::remove($link, 'encode', $this->encodeLabels); if (array_key_exists('label', $link)) { $label = $encodeLabel ? Html::encode($link['label']) : $link['label']; } else { throw new InvalidConfigException('The "label" element is required for each link.'); } if (isset($link['template'])) { $template = $link['template']; } if (isset($link['url'])) { $options = $link; Html::addCssClass($options, ['link' => 'breadcrumb']); unset($options['template'], $options['label'], $options['url']); $link = Html::a($label, $link['url'], $options); } else { $link = $label; } return strtr($template, ['{link}' => $link]); }
/** * Renders collapsible toggle button. * @return string the rendered toggle button. */ protected function renderToggleButton() { $toggleTarget = 'sidenav_' . md5(uniqid()); $this->registerToggleButtonScript($toggleTarget); return Html::a('<i class="material-icons">menu</i>', '#', ['data-activates' => $toggleTarget, 'class' => 'button-collapse']); }