WebformAccessBreadcrumbBuilder.php in Webform 8.5
File
modules/webform_access/src/Breadcrumb/WebformAccessBreadcrumbBuilder.php
View source
<?php
namespace Drupal\webform_access\Breadcrumb;
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Url;
class WebformAccessBreadcrumbBuilder implements BreadcrumbBuilderInterface {
use StringTranslationTrait;
protected $type;
public function __construct(TranslationInterface $string_translation) {
$this
->setStringTranslation($string_translation);
}
public function applies(RouteMatchInterface $route_match) {
$route_name = $route_match
->getRouteName();
if (strpos($route_name, 'webform_access') === FALSE) {
return FALSE;
}
if (!$route_match
->getRouteObject()) {
return FALSE;
}
$path = Url::fromRouteMatch($route_match)
->toString();
if (strpos($path, 'admin/structure/webform/access/') === FALSE) {
return FALSE;
}
if (strpos($path, 'admin/structure/webform/access/group/manage/') !== FALSE) {
$this->type = 'webform_access_group';
}
elseif (strpos($path, 'admin/structure/webform/access/type/manage/') !== FALSE) {
$this->type = 'webform_access_type';
}
else {
$this->type = 'webform_access';
}
return $this->type ? TRUE : FALSE;
}
public function build(RouteMatchInterface $route_match) {
$breadcrumb = new Breadcrumb();
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Home'), '<front>'));
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Administration'), 'system.admin'));
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Structure'), 'system.admin_structure'));
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Webforms'), 'entity.webform.collection'));
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Access'), 'entity.webform_access_group.collection'));
switch ($this->type) {
case 'webform_access_group':
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Groups'), 'entity.webform_access_group.collection'));
break;
case 'webform_access_type':
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Types'), 'entity.webform_access_type.collection'));
break;
}
$breadcrumb
->addCacheContexts([
'route',
]);
return $breadcrumb;
}
}