I get "Drupal\Core\Entity\Exception\UndefinedLinkTemplateException" on adding an Entity Reference of type Action such as "Make content sticky", and then saving gives an Error.

In a fresh install, in Structure, I edit the basic Article type:

  • A new field of type Entity Reference
  • Type of item to reference = Action
  • Reference method = Default

Then Create new content of type Article

  • Enter the required Title = Test
  • Enter new Entity Reference = "Make content sticky (node_make_sticky_action)"
  • And click Save

I see:

Error
The website has encountered an error. Please try again later.
Status message
Article Test has been updated.

And the Error log shows:
Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template "edit-form" found for the "action" entity type in Drupal\Core\Entity\Entity->urlInfo() (line 188 of /var/www/vhosts/my-directory/drupal8/core/lib/Drupal/Core/Entity/Entity.php).

I think it occurs if I select any Action.

Comments

iantresman’s picture

Version: 8.0.0-beta1 » 8.0.0-beta3
Priority: Normal » Critical

Still present in beta 3

berdir’s picture

Priority: Critical » Major

This doesn't seem like a critical/release-blocking bug to me. What is your use case to reference an action?

iantresman’s picture

I would have thought that any PHP error would be considered critical?

berdir’s picture

See https://www.drupal.org/node/45111 on how the priority is defined, it is only critical if it renders the whole system unusable. One broken feature that I think is not very frequently used does IMHO not qualify as breaking the whole system.

iantresman’s picture

Thanks for the link, I agree with the guidelines.

amateescu’s picture

Title: D8: Entity Reference action causes error » ER's label formatter needs to take into account that $entity->urlInfo() might throw an exception
Version: 8.0.0-beta3 » 8.0.x-dev
Component: entity system » entity_reference.module
Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new1.78 KB

This should fix it. Tests will need to be added after #2370703: ER's "autocreate" feature is mostly broken (and untested) gets in.

berdir’s picture

+++ b/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php
@@ -61,12 +62,26 @@ public function settingsSummary() {
+      if ($output_as_link) {
+        try {
+          $uri = $entity->urlInfo();
+        }
+        catch (UndefinedLinkTemplateException $e) {
+          // This exception is thrown by \Drupal\Core\Entity\Entity::urlInfo()
+          // and it means that the entity type doesn't have a link template nor
+          // a valid "uri_callback", so don't bother trying to output a link for
+          // the rest of the referenced entities.
+          $output_as_link = FALSE;
+        }
+      }

I find it very annoying that config entities overide urlInfo() and set the default to edit-form.

If it would not, then instead of checking against the exception, we could simply check for the existence of 'canonical' directly.

iantresman’s picture

@amateescu. Well done, that fixed it for me, no error. My new content now displays "Make content sticky".

I am not sure I was expecting the label. I thought maybe, I'd get either:

  • The status (ie. true/false) of whether the node had content sticky enabled/disabled, or,
  • a checkbox to enable/disable the stick option
amateescu’s picture

@Berdir, I see your point but the fact is that most config entities don't have a 'canonical' link so 'edit-form' is the next best thing.

@iantresman, well, the default formatter for entity reference fields is entity_reference_label so I'm not sure why someone would expect anything else than the label :)

iantresman’s picture

"the default formatter for entity reference fields is entity_reference_label"

Ah yes, I see that now. It just looks odd when most other fields point to their contents (value).

amateescu’s picture

Issue tags: -Needs tests
StatusFileSize
new3.97 KB
new2.12 KB

Here's the test I promised earlier.

@Berdir, thinking about it more, even if ConfigEntityBase wouldn't override urlInfo(), any other (custom) entity class could do that so checking against the exception is still the right thing to do :)

The last submitted patch, 11: 2355245-11.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 11: 2355245-11-test-only.patch, failed testing.

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new2.12 KB
new3.97 KB

Not sure what happened there, let's try again.

The last submitted patch, 14: 2355245-14-tests-only.patch, failed testing.

amateescu’s picture

Who wants to press the RTBC button? :)

berdir’s picture

Status: Needs review » Reviewed & tested by the community

@Berdir, thinking about it more, even if ConfigEntityBase wouldn't override urlInfo(), any other (custom) entity class could do that so checking against the exception is still the right thing to do :)

Right.

Let's just fix it like this then.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 7c6a23f and pushed to 8.0.x. Thanks!

  • alexpott committed 7c6a23f on
    Issue #2355245 by amateescu: ER's label formatter needs to take into...

Status: Fixed » Closed (fixed)

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