/** * 渲染选项 */ protected function renderOptions() { $html = ''; if ($this->items) { foreach ($this->items as $key => $val) { $attr = ['value' => $key]; if ($this->value !== false && $this->value == $key) { $attr['selected'] = 'true'; } $html .= Html::tag('option', $val, $attr); unset($attr); } } return $html; }
/** * 渲染工具列表 */ protected function renderTools() { if ($this->items) { $toolsContent = ''; foreach ($this->items as $item) { $innerContent = ''; if ($item['icon']) { $innerContent = Html::tag('i', '', ['class' => $item['icon']]); } $options = isset($item['options']) ? $item['options'] : []; $toolsContent .= Html::tag('a', $innerContent . $item['label'], ArrayHelper::merge(['data-original-title' => $item['title'], 'title' => $item['title']], $options)); unset($innerContent); unset($options); } return $toolsContent; } return ''; }
/** * Initializes the widget options. * This method sets the default values for various options. */ protected function initOptions() { $this->options = array_merge(['class' => 'fade', 'role' => 'dialog', 'tabindex' => -1, 'aria-hidden' => 'true'], $this->options); Html::addCssClass($this->options, 'modal'); if ($this->closeButton !== false) { $this->closeButton = array_merge(['data-dismiss' => 'modal', 'aria-hidden' => 'true', 'class' => 'close'], $this->closeButton); } if ($this->toggleButton !== false) { $this->toggleButton = array_merge(['data-toggle' => 'modal'], $this->toggleButton); if (!isset($this->toggleButton['data-target']) && !isset($this->toggleButton['href'])) { $this->toggleButton['data-target'] = '#' . $this->options['id']; } } /** * 初始化操作按钮 */ if ($this->operationButtons === false) { $this->operationButtons = Html::tag('button', Module::t('close'), ['data-dismiss' => 'modal', 'class' => 'btn btn-default']); $this->operationButtons .= Html::tag('button', Module::t('save'), ['id' => 'btn-submit', 'class' => 'btn green-meadow']); $this->footer = $this->operationButtons; } }
/** * @inheritDoc */ public static function error($model, $attribute, $options = []) { $tag = isset($options['tag']) ? $options['tag'] : 'div'; unset($options['tag'], $options['encode']); return Html::tag($tag, '', $options); }
/** * 渲染表头 * @return string */ protected function renderHeader() { if ($this->header) { $this->keys = array_keys($this->header); $renderContent = ''; foreach ($this->header as $key => $val) { $renderContent .= Html::tag('th', $val); } return Html::tag('thead', Html::tag('tr', $renderContent)); } return ''; }
/** * 设置带icon的文本或者密码输入框 * @param $options * @param bool|false $isPassword * @return array [html内容,样式] */ private function textInputIcon(&$options, $isPassword = false) { if (isset($options['typehead'])) { unset($options['typehead']); //针对想使用typehead样式的特殊处理 $spanClassOption = []; Html::addCssClass($spanClassOption, 'input-group-addon'); if (isset($options['icon-align']) && $options['icon-align'] === 'right') { if (strpos($options['class'], 'input-circle') !== false) { Html::addCssClass($spanClassOption, 'input-circle-right'); } $content = $isPassword ? Html::activePasswordInput($this->model, $this->attribute, $options) : Html::activeTextInput($this->model, $this->attribute, $options); if (isset($options['icon-link'])) { $content .= Html::tag('span', Html::tag('a', Html::tag('i', '', ['class' => $options['icon']]), ['target' => '_blank', 'href' => $options['icon-link']]), $spanClassOption); unset($options['icon-link']); } else { $content .= Html::tag('span', Html::tag('i', '', ['class' => $options['icon']]), $spanClassOption); } } else { if (strpos($options['class'], 'input-circle') !== false) { Html::addCssClass($spanClassOption, 'input-circle-left'); } if (isset($options['icon-link'])) { $content = Html::tag('span', Html::tag('a', Html::tag('i', '', ['class' => $options['icon']]), ['target' => '_blank', 'href' => $options['icon-link']]), $spanClassOption); unset($options['icon-link']); } else { $content = Html::tag('span', Html::tag('i', '', ['class' => $options['icon']]), $spanClassOption); } unset($options['icon']); $content .= $isPassword ? Html::activePasswordInput($this->model, $this->attribute, $options) : Html::activeTextInput($this->model, $this->attribute, $options); } $class = 'input-group'; } else { if (isset($options['icon-link'])) { $content = Html::tag('a', Html::tag('i', '', ['class' => $options['icon']]), ['target' => '_blank', 'href' => $options['icon-link']]); unset($options['icon-link']); } else { $content = Html::tag('i', '', ['class' => $options['icon']]); } unset($options['icon']); $content .= $isPassword ? Html::activePasswordInput($this->model, $this->attribute, $options) : Html::activeTextInput($this->model, $this->attribute, $options); $class = 'input-icon'; if (isset($options['icon-align']) && $options['icon-align'] === 'right') { $class .= ' right'; } } return [$content, $class]; }
/** * 渲染表头 * @return string */ protected function renderHeader() { if ($this->header) { $this->keys = array_keys($this->header); $renderContent = ''; if ($this->checkbox) { $renderContent .= Html::tag('th', Html::input('checkbox', '', '', ['class' => 'group-checkable', 'data-set' => '#' . $this->id . ' .checkboxes']), ['class' => 'table-checkbox']); } foreach ($this->header as $key => $val) { $renderContent .= Html::tag('th', $val); } return Html::tag('thead', Html::tag('tr', $renderContent)); } return ''; }
/** * Normalizes dropdown item options by removing tab specific keys `content` and `contentOptions`, and also * configure `panes` accordingly. * * @param string $itemNumber number of the item * @param array $items the dropdown items configuration. * @param array $panes the panes reference array. * @return boolean whether any of the dropdown items is `active` or not. * @throws InvalidConfigException */ protected function renderDropdown($itemNumber, &$items, &$panes) { $itemActive = false; foreach ($items as $n => &$item) { if (is_string($item)) { continue; } if (!array_key_exists('content', $item)) { throw new InvalidConfigException("The 'content' option is required."); } $content = ArrayHelper::remove($item, 'content'); $options = ArrayHelper::remove($item, 'contentOptions', []); Html::addCssClass($options, 'tab-pane'); if (ArrayHelper::remove($item, 'active')) { Html::addCssClass($options, 'active'); Html::addCssClass($item['options'], 'active'); $itemActive = true; } $options['id'] = ArrayHelper::getValue($options, 'id', $this->options['id'] . '-dd' . $itemNumber . '-tab' . $n); $item['url'] = '#' . $options['id']; $item['linkOptions']['data-toggle'] = 'tab'; $panes[] = Html::tag('div', $content, $options); unset($item); } return $itemActive; }
/** * 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']) { unset($items[$i]); 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, 'dropdown-header'); } 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); }
/** * (non-PHPdoc) * @see \yii\base\Widget::run() */ public function run() { $content = ''; if ($this->label) { if (isset($this->labelOptions['class'])) { $this->labelOptions['class'] = 'control-label ' . $this->labelOptions['class']; } else { Html::addCssClass($this->labelOptions, 'col-md-4'); } $content .= Html::tag('label', $this->label, $this->labelOptions); } $content .= Html::beginTag('div', $this->options); $content .= Html::beginTag('div', ['id' => $this->name . '-group', 'class' => $this->inline ? 'icheck-inline' : 'icheck-list']); if ($this->items) { foreach ($this->items as $value => $label) { $content .= Html::beginTag('label'); $content .= $this->renderContent($value); $content .= "\n" . $label . "\n"; $content .= Html::endTag('label'); } } $content .= Html::endTag('div'); $content .= Html::endTag('div'); echo Html::tag('div', $content, ['class' => 'form-group']); }