If you have a simple textfield field type in the paragraph field, in views you add this field to the fields section. Here you find an "Link to the Paragraph" checkbox. After checking the checkbox and saving the views there's an error:

Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template 'canonical' found for the 'paragraph' entity type in Drupal\Core\Entity\Entity->urlInfo() (line 198 of /var/www/html/mysite/docroot/core/lib/Drupal/Core/Entity/Entity.php).

There is a missing code in the annotation of the paragraph entity definition:
* links = {
* "canonical" = "/paragraph/manage/{paragraph_entity}",
* }
This follows a a definition in the routing.yml file and a class.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

adevms created an issue. See original summary.

miro_dietiker’s picture

We do not define canonical by intention. Because the entities we offer should only be output in context of the parent entity.

Either our views integration is wrong or views wrongly depends on a required canonical and needs a core fix.

miro_dietiker’s picture

BTW: The best start for such an issue is write a test / extend a test that shows the bug.

miro_dietiker’s picture

Note also that we currently don't have any views integration at all #2527620: views data support so if using views, we do expect things end in error.
Happy to add proper views integration.

tomasbarej’s picture

I'm experiencing the same issue (Exception) during paragraph translation. When I'm updating node translation with paragraphs I get this message. It's caused by hook path_entity_translation_delete() in path.module that it's implemented like this:

/**
 * Implements hook_entity_translation_delete().
 */
function path_entity_translation_delete(EntityInterface $translation) {
  $path = $translation->urlInfo()->getInternalPath();
  $conditions = array('source' => '/' . $path, 'langcode' => $translation->language()->getId());
  \Drupal::service('path.alias_storage')->delete($conditions);
}

The problem is that there is no fallback in case entity type doesn't have it's own URL like paragraphs and method urlInfo() throws an exception. I think this is core related issue because as miro_dietiker wrotes, paragraphs implementation of entity URL seems correct and logical.

tomasbarej’s picture

tomasbarej’s picture

stBorchert’s picture

I experienced the same error while trying to index paragraph items using Search API.
Search API always adds an UrlPreprocessor to the index which tries to get the item Url. In case of paragraphs this fails with the UndefinedLinkTemplateException because paragraphs have no link.

The attached patch fixes this problem (at least in combination with Search API). path_entity_translation_delete() is no problem anymore, since there is a check for hasLinkTemplate('canonical') now (see path.module function path_entity_translation_delete()).

Status: Needs review » Needs work

The last submitted patch, 8: no_urlInfo-2596385-8.patch, failed testing.

The last submitted patch, 8: no_urlInfo-2596385-8.patch, failed testing.

The last submitted patch, 8: no_urlInfo-2596385-8.patch, failed testing.

stBorchert’s picture

No idea, why the testbot fails ... seems like images can't be uploaded?
On my local machine the test runs without any errors.

stBorchert’s picture

Status: Needs work » Needs review

Next try ...

Berdir’s picture

The problem was core and is search_api, not paragraphs. They have to check if that link template exists before calling it. It's perfectly valid to not have one.

stBorchert’s picture

Project: Paragraphs » Search API
Component: Code » Miscellaneous
FileSize
636 bytes

Ok, moving this to Search API then.
The content entity (within Search API) itself now checks for the link template.

borisson_’s picture

The testbot is not pickup up the patch, so I just reuploaded the patch in #15.

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense. This wouldn't work on config entities, which forward to edit-url but they're not supported anyway and I'd argue that entity types that don't have a canonical link template (e.g. only an edit form) shouldn't return something there, even if they'd default to a different link template.

borisson_’s picture

I agree, rtbc++.

drunken monkey’s picture

Thanks a lot for spotting this. Of course, it makes sense that not all entities have URLs. I just thought the method would return NULL, not throw an exception, if the URL couldn't be found – because, of course, Core documents neither behavior, it just says it will always return a Url object.
Anyways, the patch looks great, too, thanks! Just changed the format a bit, and re-uploading for the test bot (to make extra sure I didn't break anything).

drunken monkey’s picture

Status: Needs review » Fixed

Committed. Thanks again!

Berdir’s picture

See #1275902: Allow entity URI callbacks to indicate that the entity has no URI, and make the User module use that for anonymous users, once core documents that NULL is a valid return value and does so for some cases, then I think updating paragraphs to do so would be correct. And possibly revert this patch.

We'll need to make sure that we do that consistently for all methods, e.g. both urlInfo() and toUrl() and so on. Maybe someone can open a follow-up for both paragraphs and search api and postpone on the core issue?

Status: Fixed » Closed (fixed)

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