Playing with drupal 8 entities, I noticed theses errors with the entity class generated :

1- When you use an entity content generated and trying to reference this entity (with an entity_reference field) from an another entity (let's say Article content type).

When you try to add a new article, you've got this fatal error.

Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template "canonical" found for the "note" entity type in Drupal\Core\Entity\Entity->urlInfo() (line 188 of /srv/www/drupal8/core/lib/Drupal/Core/Entity/Entity.php).

It's because the canonical link is missing in the annotations of the entity

2- If you reference an another entity from the entity content generated (always with an entity_reference field), you've got this fatal error when trying to add the entity_reference field.

InvalidArgumentException: Field user_id is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 339 of /srv/www/drupal8/core/lib/Drupal/Core/Entity/ContentEntityBase.php).

It's because all the functions about the owner in the Entity Class assume there is a field user_id which handle the author feature. But this field is not created in the baseFieldDefinitions.

Comments

flocondetoile’s picture

Status: Active » Needs review
StatusFileSize
new1.83 KB

Thanks for your review

flocondetoile’s picture

Issue summary: View changes
kgaut’s picture

Hello,

I was facing this issue when creating a entity with a entity_reference to another custom entity, on the entity add form.

I've just edited my two entities by adding the code proposed. And it's working !

Thanks flocondetoile !

kgaut’s picture

And I've just patched my console module, tried to generate new entities, everythings works as designed.

jmolivas’s picture

Status: Needs review » Reviewed & tested by the community

Patch tested and applied, this change will be included in next release

jmolivas’s picture

Thanks for the patch @flocondetoile

jmolivas’s picture

Fixed on new release
https://github.com/hechoendrupal/DrupalAppConsole/releases/tag/0.2.17

Try updating project

$ composer update drupal/console
jmolivas’s picture

Status: Reviewed & tested by the community » Closed (fixed)