diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 7410d06..c5cc116 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -22,7 +22,7 @@ use yii\db\ActiveQuery; use yii\helpers\Url; use yii\web\View; - use yii\widgets\Breadcrumbs; + use frontend\widgets\SeoBreadcrumbs; AppAsset::register($this); $user = \Yii::$app->user->identity; @@ -648,7 +648,7 @@ _________________________________________________________ -->

h1 ?>

- isset($this->params[ 'breadcrumbs' ]) ? $this->params[ 'breadcrumbs' ] : [], ] diff --git a/frontend/widgets/SeoBreadcrumbs.php b/frontend/widgets/SeoBreadcrumbs.php new file mode 100644 index 0000000..1e88c11 --- /dev/null +++ b/frontend/widgets/SeoBreadcrumbs.php @@ -0,0 +1,81 @@ + 'breadcrumb', + 'itemscope' => true, + 'itemtype' => " http://schema.org/BreadcrumbList" + ]; + public $encodeLabels = false; + public $itemTemplate = "
  • {link}
  • \n"; + public $homeLink = [ + 'label' => 'Главная', + 'url' => '/', + 'itemprop' => 'item', + ]; + + public $activeItemTemplate = '
  • {link}
  • '; + + public function run() + { + if (empty($this->links)) { + return; + } + $links = []; + if ($this->homeLink === null) { + $links[] = $this->renderItem_([ + 'label' => Yii::t('yii', 'Home'), + 'url' => Yii::$app->homeUrl, + ], $this->itemTemplate,1); + } elseif ($this->homeLink !== false) { + $links[] = $this->renderItem_($this->homeLink, $this->itemTemplate, 1, true); + } + foreach ($this->links as $key => $link) { + if (!is_array($link)) { + $link = ['label' => $link]; + } + $links[] = $this->renderItem_($link, isset($link['url']) ? $this->itemTemplate : $this->activeItemTemplate, $key + 2); + } + echo Html::tag($this->tag, implode('', $links), $this->options); + } + + protected function renderItem_($link, $template, $number, $home = false) + { + $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']); + if (!$home){ + $label = "".$label.""; + } + $link = Html::a($label, $link['url'], $options); + } else { + $link = $label; + } + return strtr($template, ['{link}' => $link, '{number}' => $number]); + } + } \ No newline at end of file -- libgit2 0.21.4