Call to undefined method Drupal\views_ui\Form\Ajax\ConfigHandlerExtra::getEntity() in Drupal\eca_content\Plugin\EntityReferenceSelection\EventBasedSelection->buildConfigurationForm()

Created on 5 December 2024, 5 months ago

Problem/Motivation

I'm not exactly sure what conditions trigger this issue, but it it appears that, while editing a view, and clicking "settings" on an exposed filter, \Drupal\eca_content\Plugin\EntityReferenceSelection\EventBasedSelection::buildConfigurationForm::buildConfigurationForm() can get a passed a form object of type \Drupal\views_ui\Form\Ajax\ConfigHandlerExtra, which doesn't have a getEntity() function, which results in a Error: Call to undefined method Drupal\views_ui\Form\Ajax\ConfigHandlerExtra::getEntity() in Drupal\eca_content\Plugin\EntityReferenceSelection\EventBasedSelection->buildConfigurationForm()

The problem is that the code in EventBasedSelection::buildConfigurationForm() assumes that the call to $form_state->getFormObject() will always return an EntityFormInterface...

  public function buildConfigurationForm(array $form, FormStateInterface $form_state): array {
    /** @var \Drupal\Core\Entity\EntityFormInterface $form_object */
    $form_object = $form_state->getFormObject();
    /** @var \Drupal\Core\Field\FieldDefinitionInterface $entity */
    $entity = $form_object->getEntity();
    // ...
  }

... but it appears that isn't always the case.

Interestingly, it appears that neither eca nor eca_content are used for this view. They're enabled and used for other views, just not the one that's throwing this error.

I ran across this issue while trying to determine why an exposed filter isn't limiting the list of available options to nodes of a certain type.

Steps to reproduce

(to be determined)

Proposed resolution

Only build the form if $form_object instanceof \Drupal\Core\Entity\EntityFormInterface

Remaining tasks

  1. Write a patch
  2. Review and feedback
  3. RTBC and feedback
  4. Commit and release

User interface changes

(to be determined)

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇨🇦Canada mparker17 UTC-4

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024