When fetching the object from a routeMatch object, the object is not always filled correctly when fetching it via

$route_match = \Drupal::routeMatch();
$route_match->getParameters(); // or
route_match->getParameter('taxonomy_term');

The parameter 'node' is a full correct object on the following pages in D8.0.0 (but in a previous rc-version, it was not the case):
/node/3
/node/3/delete
/node/3/workflow (using contrib Workflow module) : 'node' => object Drupal\node\Entity\Node(24)

But on the next page, the parameter is not filled with an object.
/taxonomy/term/3 : 'taxonomy_term' => object Drupal\taxonomy\Entity\Term
/taxonomy/term/3/edit : 'taxonomy_term' => object Drupal\taxonomy\Entity\Term
/taxonomy/term/3/workflow : 'taxonomy_term' => string(1) "3"

Below, you find my routing.yml data. Is this a bug? or is something missing? I tested with and without the commented lines - there is no difference.
I did not test this on user or a custom entity type, yet.

entity.node.workflow_history:
  path: '/node/{node}/workflow/{field_name}'
  defaults:
    _title: 'Workflow history'
    _controller: '\Drupal\workflow\Controller\WorkflowTransitionListController::historyOverview'
    field_name: ~
  requirements:
    _custom_access: '\Drupal\workflow\Controller\WorkflowTransitionListController::historyAccess'
    _module_dependencies: 'node'
#  options:
#    parameters:
#      entity:
#        type: entity:{entity_type}

entity.taxonomy_term.workflow_history:
  path: '/taxonomy/term/{taxonomy_term}/workflow/{field_name}'
  defaults:
    _title: 'Workflow history'
    _controller: '\Drupal\workflow\Controller\WorkflowTransitionListController::historyOverview'
    field_name: ~
  requirements:
    _custom_access: '\Drupal\workflow\Controller\WorkflowTransitionListController::historyAccess'
    _module_dependencies: 'taxonomy'
#    taxonomy_term: \d+
#  options:
#    parameters:
#      entity:
#        type: entity:{entity_type}

Comments

johnv created an issue. See original summary.

dawehner’s picture

Mh, the problem is that those pages are served by Views, mhhhhhhhhh, maybe we need to copy that over when we override it.

rcodina’s picture

Version: 8.0.0 » 8.3.x-dev
Priority: Normal » Major

I'm facing a problem which I think is related:

I have a custom module which defines custom breadcrumbs for some views and for nodes of a specific content type. When I try to do the same with taxonomy terms of a specific vocabulary, I'm facing that when I visit "taxonomy/term/%" the applies callback of my custom implementation of BreadcrumbBuilderInterface doesn't get executed. However, it gets called on "taxonomy/term/%/edit". Maybe that's the reason why the core breadcrumb builder only returns "Home / " in this case.

I'm using 8.3.0-beta1 and I hope this get fixed soon. Thanks!

<?php

namespace Drupal\custom_breadcrumb\Breadcrumb;

use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Routing\LinkGeneratorTrait;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Link;
use Drupal\taxonomy\Entity\Term;

class BlogBreadcrumbBuilder implements BreadcrumbBuilderInterface {
  use LinkGeneratorTrait;
  use StringTranslationTrait;

  /**
   * @inheritdoc
   */
  public function applies(RouteMatchInterface $route_match) {    
    // This breadcrumb apply only for blog taxonomy terms of vocabulary 'categoria_blog'.    
    $parameters = $route_match->getParameters()->all();

    /*
     * CORE BUG: applies callback gets called on "taxonomy/term/%/edit" but not in "taxonomy/term/%"
     */
    if (isset($parameters['taxonomy_term'])) {
      $term = $parameters['taxonomy_term'];

      if ($term->getVocabularyId() == 'categoria_blog') {
        return TRUE;
      }
    }

    return FALSE;
  }

  /**
   * @inheritdoc
   */
  public function build(RouteMatchInterface $route_match) {

    $parameters = $route_match->getParameters()->all();

    if (isset($parameters['taxonomy_term'])) {

      $term = $parameters['taxonomy_term'];

      // Breadcrumbs set up (cache settings are so important!).
      $breadcrumb = new \Drupal\Core\Breadcrumb\Breadcrumb();
      $breadcrumb->addCacheContexts(["url"]);
      $breadcrumb->addCacheTags(["taxonomy_term:{$term->id()}"]);

      $breadcrumb->addLink(Link::createFromRoute($term->getName(), '<none>'));
    }

    // Reverse order for this to work!!!.
    $breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>'));
    return $breadcrumb;
  }
}
rcodina’s picture

Category: Support request » Bug report
dawehner’s picture

Category: Bug report » Support request

Support questions are way better asked on stackexchange.

rcodina’s picture

@dawehner In my case it's not a support question, it's just a bug report. If you think I should open a new issue just tell me.

rcodina’s picture

rcodina’s picture

@dawehner After 14 days there is no answer on stackexchange. Do you think it's a bug?

hugronaphor’s picture

Status: Active » Closed (works as designed)

There is an answer which explains that you have to set a higher priority to your service.
https://drupal.stackexchange.com/a/235361/13633