Problem/Motivation

Steps to reproduce:

  • Enable workbench_moderation on node
  • Create a rest view showing nodes
  • Click on preview
  • Look in the logs: you have route not found exception entries in there

Problem: \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer does NOT check whether a canonical route exists

Proposed resolution

Maybe its better fixed in core ...

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner created an issue. See original summary.

timmillwood’s picture

\Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer does check to see if there is a canonical.

    if (($entity = $field_item->get('entity')->getValue()) && ($url = $entity->url('canonical'))) {
      $values['url'] = $url;
    }

So the error would only happen if an entity defines a canonical, but doesn't actually have one.

For example:
ModerationStateTransition
http://cgit.drupalcode.org/workbench_moderation/tree/src/Entity/Moderati...

It has a canonical in the links section of the annotation, but there is no route_provider for it, or canonical in workbench_moderation.routing.yml, therefore the normalizer will try to get the canonical, but a route doesn't exist for it.

Here's a quick patch for that, but could do with more info on which routes are not found for @dawehner.

timmillwood’s picture

Status: Active » Needs review
dawehner’s picture

Well, at the same time we need them in order to have some form of REST support, right?

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Most entities don't have a canonical link right now, particularly config. The situation is kinda AFU, where some things want a canonical to work, but canonical isn't required and many/most entities don't have one. For content entities it's reasonably trivial to add one, but config entities have no default view handler to rely on. So, sucky. :-(

For the time being at least, "doesn't work with REST" is better than "Fatals", so let's commit this.

josephdpurcell’s picture

Status: Reviewed & tested by the community » Fixed

Makes sense, we applied the same solution as this patch elsewhere.

Fixed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.