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

  1. Go to a paragraph bundle, e.g. https://www.example.com/admin/structure/paragraphs_type/text and click the "Automatic entity label tab"
  2. 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

Command icon 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

anybody created an issue. See original summary.

anybody’s picture

I'd rate this as bug, as the tab for setting up the auto entity label is shown, but broken.

anybody’s picture

Issue summary: View changes

m.anoune made their first commit to this issue’s fork.

m.anoune’s picture

I 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:

  • Drupal core: 10.6.7
  • PHP: 8.2.30
  • auto_entitylabel branch: 3541294-not-working-on
  • paragraphs module: 8.x-1.20

Steps I followed:

  • Installed a standard Drupal profile.
  • Enabled paragraphs and auto_entitylabel.
  • Created a new Paragraph type ("Text").
  • Navigated to the "Automatic entity label" configuration tab for this paragraph type (/admin/structure/paragraphs_type/text/auto-label).

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?

m.anoune changed the visibility of the branch 3541294-not-working-on to hidden.

anybody’s picture

Version: 8.x-3.x-dev » 8.x-3.4

I'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?

weseze’s picture

Also encountered this problem.
Not sure where to start debugging this...

Drupal core 11.3.5
Paragraphs 1.20
auto_entitylabel 3.4

dkmishra made their first commit to this issue’s fork.

dkmishra’s picture

This 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.

anybody’s picture

Status: Active » Needs work

Thanks, code style please needs to be fixed (in the MR) and tests are failing?

fox mulder’s picture

The 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:

  // Wrong (PHP attribute block):
  'edit-form' => '/admin/structure/paragraphs_type/[paragraphs_type]',

  // Correct (old docblock annotation):
  'edit-form' => '/admin/structure/paragraphs_type/{paragraphs_type}',

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.