You are here

public function TaxonomyBreadcrumb::applies in Taxonomy Breadcrumb 8

Whether this breadcrumb builder should be used to build the breadcrumb.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match.

Return value

bool TRUE if this builder should be used or FALSE to let other builders decide.

Overrides BreadcrumbBuilderInterface::applies

File

src/TaxonomyBreadcrumb.php, line 75

Class

TaxonomyBreadcrumb

Namespace

Drupal\taxonomy_breadcrumb

Code

public function applies(RouteMatchInterface $route_match) {

  // This might be a "node" with no fields, e.g. a route to a "revision" URL,
  // so we don't check for taxonomy fields on unfieldable nodes:
  $node_object = $route_match
    ->getParameters()
    ->get('node');
  $node_is_fieldable = $node_object instanceof FieldableEntityInterface;
  if ($node_is_fieldable) {
    $bundle = $node_object
      ->bundle();
    $node_types = $this->config
      ->get('taxonomy_breadcrumb_node_types');
    $exclude_include = $this->config
      ->get('taxonomy_breadcrumb_include_nodes');
    if ($exclude_include) {

      // Include option.
      if (!$node_types[$bundle]) {
        return FALSE;
      }
    }
    else {

      // Exclude option.
      if ($node_types[$bundle]) {
        return FALSE;
      }
    }
    return TRUE;
  }
  return FALSE;
}