예제 #1
0
 /**
  * Renders the detail view.
  * This is the main entry of the whole detail view rendering.
  */
 public function run()
 {
     $rows = [];
     $i = 0;
     foreach ($this->attributes as $attribute) {
         $rows[] = $this->renderAttribute($attribute, $i++);
     }
     $options = $this->options;
     $tag = ArrayHelper::remove($options, 'tag', 'table');
     echo Html::tag($tag, implode("\n", $rows), $options);
 }
예제 #2
0
 /**
  * Renders the sorter.
  * @return string the rendering result
  */
 public function renderSorter()
 {
     $sort = $this->dataProvider->getSort();
     if ($sort === false || empty($sort->attributes) || $this->dataProvider->getCount() <= 0) {
         return '';
     }
     /* @var $class LinkSorter */
     $sorter = $this->sorter;
     $class = ArrayHelper::remove($sorter, 'class', LinkSorter::className());
     $sorter['sort'] = $sort;
     $sorter['view'] = $this->getView();
     return $class::widget($sorter);
 }
예제 #3
0
 /**
  * Recursively renders the menu items (without the container tag).
  * @param array $items the menu items to be rendered recursively
  * @return string the rendering result
  */
 protected function renderItems($items)
 {
     $n = count($items);
     $lines = [];
     foreach ($items as $i => $item) {
         $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', []));
         $tag = ArrayHelper::remove($options, 'tag', 'li');
         $class = [];
         if ($item['active']) {
             $class[] = $this->activeCssClass;
         }
         if ($i === 0 && $this->firstItemCssClass !== null) {
             $class[] = $this->firstItemCssClass;
         }
         if ($i === $n - 1 && $this->lastItemCssClass !== null) {
             $class[] = $this->lastItemCssClass;
         }
         if (!empty($class)) {
             if (empty($options['class'])) {
                 $options['class'] = implode(' ', $class);
             } else {
                 $options['class'] .= ' ' . implode(' ', $class);
             }
         }
         $menu = $this->renderItem($item);
         if (!empty($item['items'])) {
             $submenuTemplate = ArrayHelper::getValue($item, 'submenuTemplate', $this->submenuTemplate);
             $menu .= strtr($submenuTemplate, ['{items}' => $this->renderItems($item['items'])]);
         }
         if ($tag === false) {
             $lines[] = $menu;
         } else {
             $lines[] = Html::tag($tag, $menu, $options);
         }
     }
     return implode("\n", $lines);
 }
예제 #4
0
 /**
  * Renders a single data model.
  * @param mixed $model the data model to be rendered
  * @param mixed $key the key value associated with the data model
  * @param integer $index the zero-based index of the data model in the model array returned by [[dataProvider]].
  * @return string the rendering result
  */
 public function renderItem($model, $key, $index)
 {
     if ($this->itemView === null) {
         $content = $key;
     } elseif (is_string($this->itemView)) {
         $content = $this->getView()->render($this->itemView, array_merge(['model' => $model, 'key' => $key, 'index' => $index, 'widget' => $this], $this->viewParams));
     } else {
         $content = call_user_func($this->itemView, $model, $key, $index, $this);
     }
     $options = $this->itemOptions;
     $tag = ArrayHelper::remove($options, 'tag', 'div');
     if ($tag !== false) {
         $options['data-key'] = is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : (string) $key;
         return Html::tag($tag, $content, $options);
     } else {
         return $content;
     }
 }
예제 #5
0
 /**
  * Registers a JS file.
  * @param string $url the JS file to be registered.
  * @param array $options the HTML attributes for the script tag. The following options are specially handled
  * and are not treated as HTML attributes:
  *
  * - `depends`: array, specifies the names of the asset bundles that this JS file depends on.
  * - `position`: specifies where the JS script tag should be inserted in a page. The possible values are:
  *     * [[POS_HEAD]]: in the head section
  *     * [[POS_BEGIN]]: at the beginning of the body section
  *     * [[POS_END]]: at the end of the body section. This is the default value.
  *
  * Please refer to [[Html::jsFile()]] for other supported options.
  *
  * @param string $key the key that identifies the JS script file. If null, it will use
  * $url as the key. If two JS files are registered with the same key, the latter
  * will overwrite the former.
  */
 public function registerJsFile($url, $options = [], $key = null)
 {
     $url = Leaps::getAlias($url);
     $key = $key ?: $url;
     $depends = ArrayHelper::remove($options, 'depends', []);
     if (empty($depends)) {
         $position = ArrayHelper::remove($options, 'position', self::POS_END);
         $this->jsFiles[$position][$key] = Html::jsFile($url, $options);
     } else {
         $this->getAssetManager()->bundles[$key] = new AssetBundle(['baseUrl' => '', 'js' => [strncmp($url, '//', 2) === 0 ? $url : ltrim($url, '/')], 'jsOptions' => $options, 'depends' => (array) $depends]);
         $this->registerAssetBundle($key);
     }
 }
예제 #6
0
 /**
  * Renders the opening tag of the field container.
  * @return string the rendering result.
  */
 public function begin()
 {
     if ($this->form->enableClientScript) {
         $clientOptions = $this->getClientOptions();
         if (!empty($clientOptions)) {
             $this->form->attributes[] = $clientOptions;
         }
     }
     $inputID = Html::getInputId($this->model, $this->attribute);
     $attribute = Html::getAttributeName($this->attribute);
     $options = $this->options;
     $class = isset($options['class']) ? [$options['class']] : [];
     $class[] = "field-{$inputID}";
     if ($this->model->isAttributeRequired($attribute)) {
         $class[] = $this->form->requiredCssClass;
     }
     if ($this->model->hasErrors($attribute)) {
         $class[] = $this->form->errorCssClass;
     }
     $options['class'] = implode(' ', $class);
     $tag = ArrayHelper::remove($options, 'tag', 'div');
     return Html::beginTag($tag, $options);
 }
예제 #7
0
 /**
  * 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;
         unset($options['template'], $options['label'], $options['url']);
         $link = Html::a($label, $link['url'], $options);
     } else {
         $link = $label;
     }
     return strtr($template, ['{link}' => $link]);
 }