Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip link headers for non-canonicalizable entities #781

Merged
merged 4 commits into from
Jul 29, 2020

Conversation

adam-vessey
Copy link

What does this Pull Request do?

Addresses Islandora/documentation#1551, allowing for content making reference to non-canonicalizable entities (such as blocks) to be manipulated and viewed.

What's new?

We use Entity::toUrl() to generate the URL, and catch its UndefinedLinkTemplateException exception.

How should this be tested?

  • Create a node bundle which can make references to blocks with an entity reference field
  • Make a node with a reference to a block

In 1.1.1--prior to this change--you might experience uncaught exceptions, such as:

Symfony\Component\Routing\Exception\RouteNotFoundException: Route "entity.block.canonical" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 208 of /opt/www/drupal/core/lib/Drupal/Core/Routing/RouteProvider.php).

With the new URL generation, we catch the more-specific UndefinedLinkTemplateException exception, and skip attempting to create a link entry for it.

Additional Notes:

The docs on EntityInterface::toUrl() indicate:

If the path is not set in the links array, the uri_callback function is used for setting the path. If this does not exist and the link relationship type is canonical, the path is set using the default template: entity/entityType/id.

... This does not appear to happen, with the exception being thrown instead of whatever "default template" being used, despite the nearby inline documentation.

Interested parties

@Islandora/8-x-committers

... allow for catching exceptions for entities without canonical
URLs.
... also, throw in the other throws declaration.
Copy link

@dannylamb dannylamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as described. Thanks @adam-vessey! 🙇‍♂️

@dannylamb dannylamb merged commit bfa2c39 into Islandora:8.x-1.x Jul 29, 2020
@adam-vessey adam-vessey deleted the 8.x-1.x-exception-avoidance branch July 18, 2022 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants