class ViewsBreadCrumbBuilder in Views breadcrumb 8.2
Same name and namespace in other branches
- 8 src/Breadcrumb/ViewsBreadcrumbBuilder.php \Drupal\views_breadcrumb\Breadcrumb\ViewsBreadCrumbBuilder
Hierarchy
- class \Drupal\views_breadcrumb\Breadcrumb\ViewsBreadCrumbBuilder implements BreadcrumbBuilderInterface
Expanded class hierarchy of ViewsBreadCrumbBuilder
File
- src/
Breadcrumb/ ViewsBreadcrumbBuilder.php, line 12
Namespace
Drupal\views_breadcrumb\BreadcrumbView source
class ViewsBreadCrumbBuilder implements BreadcrumbBuilderInterface {
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $attributes) {
$parameters = $attributes
->getParameters()
->all();
if (!empty($parameters['view_id'])) {
return TRUE;
}
}
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match) {
$breadcrumb = new Breadcrumb();
$breadcrumb
->addLink(Link::createFromRoute('Home', '<front>'));
$path = \Drupal::service('path.current')
->getPath();
$url_object = \Drupal::service('path.validator')
->getUrlIfValid($path);
$route_name = $url_object
->getRouteName();
$query = \Drupal::database()
->select('menu_tree', 'm');
$query
->fields('m');
$query
->condition('m.route_name', $route_name);
$query
->condition('m.provider', 'views');
$result = $query
->execute()
->fetchAssoc();
$depth = $result['depth'];
if (empty($result)) {
return $breadcrumb;
}
for ($i = 1; $i < $depth; $i++) {
$query = \Drupal::database()
->select('menu_tree', 'm');
$query
->fields('m');
$query
->condition('m.mlid', $result['p' . $i]);
$result1 = $query
->execute()
->fetchAssoc();
$breadcrumb
->addLink(Link::createFromRoute(unserialize($result1['title']), $result1['route_name']));
}
return $breadcrumb;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ViewsBreadCrumbBuilder:: |
public | function |
Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface:: |
|
ViewsBreadCrumbBuilder:: |
public | function |
Builds the breadcrumb. Overrides BreadcrumbBuilderInterface:: |