Missing entity breaks autocomplete for single value in EntityReference::statesHandler

Created on 31 August 2023, over 1 year ago

Problem/Motivation

Using a taxonomy term reference as the "Controlled by" we had a reference to a non existing term id in there and it failed with:

    The website encountered an unexpected error. Please try again later.
    TypeError: Drupal\conditional_fields\Plugin\conditional_fields\handler\EntityReference::getAutocompleteSuggestions(): Argument #1 ($entity) must be of type Drupal\Core\Entity\EntityInterface, null given, called in /var/www/html/public/modules/contrib/conditional_fields/src/Plugin/conditional_fields/handler/EntityReference.php on line 34 in Drupal\conditional_fields\Plugin\conditional_fields\handler\EntityReference->getAutocompleteSuggestions() (line 64 of modules/contrib/conditional_fields/src/Plugin/conditional_fields/handler/EntityReference.php).

    Drupal\conditional_fields\Plugin\conditional_fields\handler\EntityReference->getAutocompleteSuggestions(NULL) (Line: 34) Drupal\conditional_fields\Plugin\conditional_fields\handler\EntityReference->statesHandler(Array, Array, Array) (Line: 283) Drupal\conditional_fields\ConditionalFieldsFormHelper->getState('field_ps_name_term', Array, Array) (Line: 183) Drupal\conditional_fields\ConditionalFieldsFormHelper->processDependeeFields(Array, Array, Array, Array) (Line: 111) Drupal\conditional_fields\ConditionalFieldsFormHelper->processDependentFields() (Line: 85) Drupal\conditional_fields\ConditionalFieldsFormHelper->afterBuild(Array, Object) (Line: 187) conditional_fields_form_after_build(Array, Object) call_user_func_array('conditional_fields_form_after_build', Array) (Line: 1083) Drupal\Core\Form\FormBuilder->doBuildForm('application_post_secondary_edit_form', Array, Object) (Line: 579) Drupal\Core\Form\FormBuilder->processForm('application_post_secondary_edit_form', Array, Object) (Line: 325) Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 600) Drupal\conditional_fields\Form\ConditionalFieldEditForm->getDummyField('application_post_secondary', 'application_post_secondary', Array, Object, Array) (Line: 171) Drupal\conditional_fields\Form\ConditionalFieldEditForm->buildForm(Array, Object, 'application_post_secondary', 'application_post_secondary', 'field_ps_name', 'ad2d2db9-7b5b-4fbb-8afd-f6e5cdae6224') call_user_func_array(Array, Array) (Line: 536) Drupal\Core\Form\FormBuilder->retrieveForm('conditional_field_edit_form', Object) (Line: 283) Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73) Drupal\Core\Controller\FormController->getContentResult(Object, Object) call_user_func_array(Array, Array) (Line: 123) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580) Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169) Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81) Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58) Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48) Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106) Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85) Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23) Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718) Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

Proposed resolution

The multi-value checks if the $entity is empty, let's do that for both.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs review

Version

4.0

Component

Code

Created by

🇨🇦Canada joelpittet Vancouver

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