Problem/Motivation
When viewing a taxonomy page like /taxonomy/term/1, the following error occurs:
Symfony\Component\Routing\Exception\RouteNotFoundException: Route "entity.taxonomy_term.version_history" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 186 of core/lib/Drupal/Core/Routing/RouteProvider.php).
Drupal\Core\Routing\UrlGenerator->getRoute('entity.taxonomy_term.version_history') (Line: 280)
Drupal\Core\Routing\UrlGenerator->generateFromRoute('entity.taxonomy_term.version_history', Array, Array, 1) (Line: 105)
Drupal\Core\Render\MetadataBubblingUrlGenerator->generateFromRoute('entity.taxonomy_term.version_history', Array, Array, ) (Line: 749)
Drupal\Core\Url->toString() (Line: 286)
Drupal\Core\Entity\Entity->url('version-history') (Line: 100)
taxonomy_page_attachments_alter(Array, NULL, NULL) (Line: 501)
Drupal\Core\Extension\ModuleHandler->alter('page_attachments', Array) (Line: 304)
Drupal\Core\Render\MainContent\HtmlRenderer->invokePageAttachmentHooks(Array) (Line: 273)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 98)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 77)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 626)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
This is with:
- workspace version: 1.0-alpha1
- Drupal core version: 8.1.0
The problem appears to be due to workspace/src/EntityTypeInfo.php in addRevisionLinks()
:
if (!$entity_type->hasLinkTemplate('version-history')) {
$entity_type->setLinkTemplate('version-history', $entity_type->getLinkTemplate('canonical') . '/revisions');
}
because in taxonomy.module, taxonomy_page_attachments_alter()
:
if ($route_match->getRouteName() == 'entity.taxonomy_term.canonical' && ($term = $route_match->getParameter('taxonomy_term')) && $term instanceof TermInterface) {
foreach ($term->uriRelationships() as $rel) {
// Set the URI relationships, like canonical.
$page['#attached']['html_head_link'][] = array(
array(
'rel' => $rel,
'href' => $term->url($rel), // This line here.
),
TRUE,
);
...
$term->url($rel)
, results in a call Entity::url()
which in turn has: $this->toUrl($rel)
, which creates a new Url object:
// where $route_name = entity.taxonomy_term.version_history and
// $route_parameters = [ taxonomy_term => "1" ]
$uri = new Url($route_name, $route_parameters);
and attempts to return $uri->toString();
. (see Url::toString()
)
If we look at Url::toString()
, we see that it uses urlGenerator
to get the relative URL. However, RouteProvider::getRouteByName()
throws an exception since there's no matching route found.
Proposed resolution
In EntityTypeInfo.php in addRevisionLinks()
, perhaps additional conditions need to be added to this if block?
if (!$entity_type->hasLinkTemplate('version-history')) {
$entity_type->setLinkTemplate('version-history', $entity_type->getLinkTemplate('canonical') . '/revisions');
}
I'm not sure why Taxonomy terms have the version-history template. I don't see version-history in the annotations in Term.php.
Comments
Comment #2
timmillwoodThanks for reporting this, I have been able to replicate so will post a fix shortly.
Comment #4
timmillwood