Undefined property: DependencyHelper::$entity_type

Created on 27 December 2024, 4 months ago

Problem/Motivation

When creating content I ran into the following error, stack trace:

Warning: Undefined property: Drupal\conditional_fields\DependencyHelper::$entity_type in Drupal\conditional_fields\DependencyHelper->resolveBundleDependencies() (line 156 of modules/contrib/conditional_fields/src/DependencyHelper.php).
Drupal\conditional_fields\DependencyHelper->resolveBundleDependencies() (Line: 140)
Drupal\conditional_fields\DependencyHelper->getBundleDependencies() (Line: 219)
Drupal\conditional_fields\ConditionalFieldsElementAlterHelper->loadDependencies() (Line: 109)
Drupal\conditional_fields\ConditionalFieldsElementAlterHelper->afterBuild() (Line: 102)
conditional_fields_element_after_build()
call_user_func_array() (Line: 1077)
Drupal\Core\Form\FormBuilder->doBuildForm() (Line: 1069)
Drupal\Core\Form\FormBuilder->doBuildForm() (Line: 1069)
Drupal\Core\Form\FormBuilder->doBuildForm() (Line: 579)
Drupal\Core\Form\FormBuilder->processForm() (Line: 326)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm() (Line: 127)
Drupal\block_content\Controller\BlockContentController->addForm() (Line: 92)
Drupal\block_content\Controller\BlockContentController->add()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

After updating to Drupal 10.4.0 & PHP 8.3.13 and attempting to add/edit existing content I ran into the error above.

Proposed resolution

update src/DependencyHelper.php with the following adjustments:

  public function __construct(
    string $entity_type,
    string $bundle,
    ModuleHandlerInterface $module_handler,
    EntityTypeManagerInterface $entity_type_manager
  ) {
    $this->entityType = $entity_type; // Use the correctly declared property.
    $this->bundle = $bundle;
    $this->moduleHandler = $module_handler;
    $this->entityTypeManager = $entity_type_manager;
  }
  /**
   * Resolve a bundle's dependencies.
   */
  protected function resolveBundleDependencies($dependent_fields) {
    $this->dependencies[$this->entityType][$this->bundle] = []; // Use $this->entityType.
    foreach ($dependent_fields as $dependent => $field) {
      $this->dependent = $dependent;
      $this->dependentField = $field;
      $this->resolveFieldDependencies();
    }
  }

Remaining tasks

n/a

User interface changes

n/a

API changes

n/a

Data model changes

n/a

πŸ› Bug report
Status

Needs review

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jrajewski1073 Littleton, CO

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