Yii2 ActionFilter which automatically append module as breadcrumb item if his id exists in requested route.
The preferred way to install this extension is through composer.
Either run
$ composer require itnelo/yii2-breadcrumbs-filter:~1.0
or add
"itnelo/yii2-breadcrumbs-filter": "~1.0"
to the require
section of your composer.json
file.
Attach behavior to module:
public function behaviors()
{
return array_merge(parent::behaviors(), [
'breadcrumbs' => [
'class' => \itnelo\filters\BreadcrumbsFilter::className(),
]
]);
}
In view file (perhaps, layout):
<div class="container">
<?= \yii\widgets\Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
</div>
You can unify building of site breadcrumbs navigation by extending yii\base\Module. It will guarantee what all modules in requested route gets their place in breadcrumbs widget. Example:
use yii\base\Module as BaseModule;
use itnelo\filters\BreadcrumbsFilter;
class Module extends BaseModule
{
/**
* Module name
* @var string
*/
public $name = 'My Module';
/**
* Enable/Disable breadcrumbs natigation via app\components\filters\BreadcrumbsFilter
* For module and submodules, without affects on parent module
* @var bool
*/
public $breadcrumbs = true;
/**
* Array of [routes|controllers|actions] names which shouldn't have breadcrumbs
* ['*'] means what breadcrumbs navigation disabled for all controllers and actions (direct childs)
* For module and submodules, without affects on parent module
* @var bool
*/
public $breadcrumbsExceptRoutes = [];
/**
* @inheritdoc
*/
public function behaviors()
{
$behaviors = [];
if ($this->breadcrumbs) {
$behaviors['breadcrumbs'] = [
'class' => BreadcrumbsFilter::className(),
'label' => $this->name,
'defaultRoute' => $this->defaultRoute,
'exceptRoutes' => $this->breadcrumbsExceptRoutes,
];
}
return array_merge(parent::behaviors(), $behaviors);
}
}
The MIT License (MIT). Please see License File for more information.