Problem/Motivation
When trying to set up automatic entity labels on a paragraph bundle, I get the following error:
Error: Call to a member function id() on null in Drupal\auto_entitylabel\Form\AutoEntityLabelForm->__construct()
Still the tab is available at /admin/structure/paragraphs_type/[paragraphs_type]/auto-label (real url!)
Please note that the paragraph type ID is missing in the real URL and instead the URL is like shown above, which surely creates the issue.
Steps to reproduce
- Go to a paragraph bundle, e.g. https://www.example.com/admin/structure/paragraphs_type/text and click the "Automatic entity label tab"
- See the broken link and error message
Replacing the placeholder with the bundle ID, e.g. "text" does not work and leads to a "Page not found" error.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
anybodyI'd rate this as bug, as the tab for setting up the auto entity label is shown, but broken.
Comment #3
anybodyComment #5
m.anoune commentedI tried to reproduce this issue on a fresh installation, but everything worked as expected for me. The "Automatic entity label" configuration tab for a Paragraph type loaded perfectly with a 200 HTTP code, and no PHP Fatal Error was triggered.
My testing environment:
Steps I followed:
Result: The form displayed correctly without any Call to a member function id() on null error.
@anybody : Could you provide a bit more context about your setup? Are you using any specific modules that might alter the paragraph entity form (like inline_entity_form or field_group)? Also, which exact version of Drupal core were you using when you encountered the crash?
Comment #7
anybodyI'm still able to reproduce this.
The link in the tabs on top at
https://www.example.com/admin/structure/paragraphs_type/text/fields still contains the brackets:
https://www.example.com/admin/structure/paragraphs_type/[paragraphs_type]/auto-label<< This is NOT an example, the string[paragraphs_type]is part of the link exactly.Drupal Core is 11.3.8
Auto Entitylabel is 8.x-3.4
As already the link is broken, I don't know which of the many contrib modules could cause that. Can you reproduce this with the versions described?
Comment #8
weseze commentedAlso encountered this problem.
Not sure where to start debugging this...
Drupal core 11.3.5
Paragraphs 1.20
auto_entitylabel 3.4
Comment #11
dkmishra commentedThis patch fixes a fatal error when configuring Auto Entity Label for contrib/custom entity types whose route parameters do not resolve to bundle config entities. Previously the form assumed route parameters always returned an entity object and directly called: $entity_type->id() . This caused the following error for contrib-provided entities.
Comment #12
anybodyThanks, code style please needs to be fixed (in the MR) and tests are failing?
Comment #13
fox mulder commentedThe root cause of this issue is actually an upstream bug in the Paragraphs module itself, tracked in paragraphs #3587229.
In paragraphs/src/Entity/ParagraphsType.php, the #[ConfigEntityType] PHP attribute block (which takes precedence over the old docblock annotation in Drupal 11.3+) has a syntax error in its links definition — it uses square brackets instead of curly braces for the route parameter placeholder:
Because of this, Drupal's routing system cannot resolve the {paragraphs_type} parameter from the link template, which causes auto_entitylabel to receive null when looking up the entity from the route — hence the Call to a member function id() on null error, and the malformed URL /admin/structure/paragraphs_type/[paragraphs_type]/auto-label appearing in the tab link.
The fix is in paragraphs MR !251 (changing [paragraphs_type] to {paragraphs_type} in the PHP attribute). Once that is merged and released, this auto_entitylabel issue should resolve itself for Paragraphs bundles.
That said, the null-check proposed in MR !42 is still a worthwhile defensive fix — any other contrib entity type that has the same square-bracket typo in its PHP attribute would trigger the same error in auto_entitylabel.