Problem/Motivation
An error occurs when attempting to view an entity route for an entity that doesn't implement hasField.
Steps to reproduce
View an entity route for an entity without hasField. In my instance, it was viewing a Search API index. The error produced was:
Error: Call to undefined method Drupal\search_api\Entity\Index::hasField() in /var/www/html/web/modules/contrib/easy_breadcrumb/src/TitleResolver.php
Proposed resolution
Remaining tasks
Test for hasField on the entity before using it
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | easy_breadcrumb-fix-entities-without-hasField-3253835-6.patch | 1.05 KB | pianomansam |
Issue fork easy_breadcrumb-3253835
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
pianomansam commentedHere is a small patch that tests for hasField before attempting to use it
Comment #3
pianomansam commentedAnother attempt at creating the patch
Comment #4
greg boggsLooks like a reasonable work around for a Search API Bug, but we should probably fix this in Search API too.
Comment #5
pianomansam commented@Greg Boggs is it a bug with Search API? From the sounds of it, not all entities routes will be for fieldable entities. The hasField method seems to imply it's a fieldable entity, which might not be true.
Comment #6
pianomansam commented@Greg Boggs I read up more about this, and this isn't a problem with Search API. It's a bug here in easy_breadcrumb. In looking for the alternative field on the current routes entity, the code currently evaluates any entity route. But not all entity routes are fieldable entities. Trying to use hasField on non-fieldable entities (like Search API indexes) causes the error.
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
I've added a new patch that intelligently looks to see if the route's entity is a FieldableEntityInterface entity before using hasField.
Comment #7
greg boggsThat looks perfect. Thank you for figuring this out! Can you open a merge request?
Comment #9
pianomansam commented@Greg Boggs merge request created
Comment #12
greg boggs