コード例 #1
0
ファイル: Panel.php プロジェクト: chervand/yii2-bootstrap
 /**
  * @param string $name section name, e.g. 'heading', 'body' or 'footer'
  * @param array|string $section todo: section description
  * @return array
  * @throws InvalidConfigException
  */
 public function prepareSection($name, &$section)
 {
     if (is_string($section)) {
         $section = ['content' => $section];
     } elseif (is_callable($section)) {
         $section = ['view' => $section];
     }
     if (is_array($section) && isset($section['view'])) {
         if (is_string($section['view'])) {
             $params = ArrayHelper::getValue($section, 'params', []);
             $section['content'] = $this->getView()->render($section['view'], $params);
         } elseif (is_callable($section['view'])) {
             $section['content'] = call_user_func($section['view'], $this);
         }
     }
     if (isset($section['content']) && !is_string($section['content'])) {
         throw new InvalidConfigException('Invalid attribute type, string expected.');
     }
     $section['options'] = ArrayHelper::getValue($section, 'options', []);
     Html::addCssClass($section['options'], ['widget' => 'panel-' . $name]);
     return $section;
 }
コード例 #2
0
ファイル: Nav.php プロジェクト: chervand/yii2-bootstrap
 /**
  * @inheritdoc
  */
 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', '#');
     $name = ArrayHelper::getValue($item, 'name');
     $description = ArrayHelper::getValue($item, 'description');
     $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
     $options['id'] = $name;
     $options['title'] = $description;
     if (isset($item['active'])) {
         $active = ArrayHelper::remove($item, 'active', false);
     } else {
         $active = $this->isItemActive($item);
     }
     if ($items !== null) {
         $linkOptions['data-toggle'] = $this->toggle;
         Html::addCssClass($options, ['widget' => $this->toggle]);
         Html::addCssClass($linkOptions, ['widget' => $this->toggle . '-toggle']);
         if ($this->dropDownCaret !== '') {
             $label .= ' ' . $this->dropDownCaret;
         }
         if (is_array($items)) {
             if ($this->activateItems) {
                 $items = $this->isChildActive($items, $active);
             }
             if ($this->toggle == static::TOGGLE_COLLAPSE) {
                 $linkOptions['data-target'] = '#' . $this->collapseIdPrefix . $name;
                 $items = $this->renderCollapse($items, $item);
             } else {
                 $items = $this->renderDropdown($items, $item);
             }
         }
     }
     if ($this->activateItems && $active) {
         Html::addCssClass($options, 'active');
     }
     return Html::tag('li', Html::a($label, $url, $linkOptions) . $items, $options);
 }