예제 #1
0
 /**
  * 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 (isset($item['visible']) && !$item['visible']) {
             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, ['widget' => '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 $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);
 }
 /**
  * Generates a bar
  * @param integer $percent the percentage of the bar
  * @param string $label, optional, the label to display at the bar
  * @param array $options the HTML attributes of the bar
  * @return string the rendering result.
  */
 protected function renderBar($percent, $label = '', $options = [])
 {
     $defaultOptions = ['role' => 'progressbar', 'aria-valuenow' => $percent, 'aria-valuemin' => 0, 'aria-valuemax' => 100, 'style' => "width:{$percent}%"];
     $options = array_merge($defaultOptions, $options);
     Html::addCssClass($options, ['widget' => 'progress-bar']);
     $out = Html::beginTag('div', $options);
     $out .= $label;
     $out .= Html::tag('span', \Yii::t('yii', '{percent}% Complete', ['percent' => $percent]), ['class' => 'sr-only']);
     $out .= Html::endTag('div');
     return $out;
 }
 /**
  * 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], $this->options);
     Html::addCssClass($this->options, ['widget' => 'modal']);
     if ($this->clientOptions !== false) {
         $this->clientOptions = array_merge(['show' => false], $this->clientOptions);
     }
     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'];
         }
     }
 }
 /**
  * Renders a single collapsible item group
  * @param string $header a label of the item group [[items]]
  * @param array $item a single item from [[items]]
  * @param integer $index the item index as each item group content must have an id
  * @return string the rendering result
  * @throws InvalidConfigException
  */
 public function renderItem($header, $item, $index)
 {
     if (array_key_exists('content', $item)) {
         $id = $this->options['id'] . '-collapse' . $index;
         $options = ArrayHelper::getValue($item, 'contentOptions', []);
         $options['id'] = $id;
         Html::addCssClass($options, ['widget' => 'panel-collapse', 'collapse' => 'collapse']);
         $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
         if ($encodeLabel) {
             $header = Html::encode($header);
         }
         $headerToggle = Html::a($header, '#' . $id, ['class' => 'collapse-toggle', 'data-toggle' => 'collapse', 'data-parent' => '#' . $this->options['id']]) . "\n";
         $header = Html::tag('h4', $headerToggle, ['class' => 'panel-title']);
         if (is_string($item['content']) || is_object($item['content'])) {
             $content = Html::tag('div', $item['content'], ['class' => 'panel-body']) . "\n";
         } elseif (is_array($item['content'])) {
             $content = Html::ul($item['content'], ['class' => 'list-group', 'itemOptions' => ['class' => 'list-group-item'], 'encode' => false]) . "\n";
             if (isset($item['footer'])) {
                 $content .= Html::tag('div', $item['footer'], ['class' => 'panel-footer']) . "\n";
             }
         } else {
             throw new InvalidConfigException('The "content" option should be a string, array or object.');
         }
     } else {
         throw new InvalidConfigException('The "content" option is required.');
     }
     $group = [];
     $group[] = Html::tag('div', $header, ['class' => 'panel-heading']);
     $group[] = Html::tag('div', $content, $options);
     return implode("\n", $group);
 }
 /**
  * Renders a file input.
  * This method will generate the "name" and "value" tag attributes automatically for the model attribute
  * unless they are explicitly specified in `$options`.
  * @param array $options the tag options in terms of name-value pairs. These will be rendered as
  * the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]].
  *
  * If you set a custom `id` for the input element, you may need to adjust the [[$selectors]] accordingly.
  *
  * @return $this the field object itself
  */
 public function fileInput($options = [])
 {
     // https://github.com/yiisoft/yii2/pull/795
     $this->template = $this->fileInputTemplate;
     if ($this->inputOptions !== ['class' => 'form-control']) {
         $options = array_merge($this->inputOptions, $options);
     }
     // https://github.com/yiisoft/yii2/issues/8779
     if (!isset($this->form->options['enctype'])) {
         $this->form->options['enctype'] = 'multipart/form-data';
     }
     $this->adjustLabelFor($options);
     $this->parts['{input}'] = Html::activeFileInput($this->model, $this->attribute, $options);
     return $this;
 }
 /**
  * Generates the button dropdown.
  * @return string the rendering result.
  */
 protected function renderButton()
 {
     Html::addCssClass($this->options, ['widget' => 'btn']);
     $label = $this->label;
     if ($this->encodeLabel) {
         $label = Html::encode($label);
     }
     if ($this->split) {
         $options = $this->options;
         $this->options['data-toggle'] = 'dropdown';
         Html::addCssClass($this->options, ['toggle' => 'dropdown-toggle']);
         unset($this->options['id']);
         $splitButton = Button::widget(['label' => '<span class="caret"></span>', 'encodeLabel' => false, 'options' => $this->options, 'view' => $this->getView()]);
     } else {
         $label .= ' <span class="caret"></span>';
         $options = $this->options;
         if (!isset($options['href'])) {
             $options['href'] = '#';
         }
         Html::addCssClass($options, ['toggle' => 'dropdown-toggle']);
         $options['data-toggle'] = 'dropdown';
         $splitButton = '';
     }
     return Button::widget(['tagName' => $this->tagName, 'label' => $label, 'options' => $options, 'encodeLabel' => false, 'view' => $this->getView()]) . "\n" . $splitButton;
 }
 /**
  * Initializes the widget options.
  * This method sets the default values for various options.
  */
 protected function initOptions()
 {
     Html::addCssClass($this->options, ['alert', 'fade', 'in']);
     if ($this->closeButton !== false) {
         $this->closeButton = array_merge(['data-dismiss' => 'alert', 'aria-hidden' => 'true', 'class' => 'close'], $this->closeButton);
     }
 }
 /**
  * Renders previous and next control buttons.
  * @throws InvalidConfigException if [[controls]] is invalid.
  */
 public function renderControls()
 {
     if (isset($this->controls[0], $this->controls[1])) {
         return Html::a($this->controls[0], '#' . $this->options['id'], ['class' => 'left carousel-control', 'data-slide' => 'prev']) . "\n" . Html::a($this->controls[1], '#' . $this->options['id'], ['class' => 'right carousel-control', 'data-slide' => 'next']);
     } elseif ($this->controls === false) {
         return '';
     } else {
         throw new InvalidConfigException('The "controls" property must be either false or an array of two elements.');
     }
 }
 /**
  * Renders the widget.
  */
 public function run()
 {
     BootstrapAsset::register($this->getView());
     return Html::tag('div', $this->renderButtons(), $this->options);
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (!in_array($this->layout, ['default', 'horizontal', 'inline'])) {
         throw new InvalidConfigException('Invalid layout type: ' . $this->layout);
     }
     if ($this->layout !== 'default') {
         Html::addCssClass($this->options, 'form-' . $this->layout);
     }
     parent::init();
 }
 /**
  * Renders collapsible toggle button.
  * @return string the rendering toggle button.
  */
 protected function renderToggleButton()
 {
     $bar = Html::tag('span', '', ['class' => 'icon-bar']);
     $screenReader = "<span class=\"sr-only\">{$this->screenReaderToggleText}</span>";
     return Html::button("{$screenReader}\n{$bar}\n{$bar}\n{$bar}", ['class' => 'navbar-toggle', 'data-toggle' => 'collapse', 'data-target' => "#{$this->containerOptions['id']}"]);
 }
예제 #13
0
 /**
  * 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;
 }
 /**
  * @inheritdoc
  */
 public function textInput($options = [])
 {
     Html::addCssClass($options, $this->addClass);
     var_dump($options);
     return parent::textInput($options);
 }