Can not add field states to paragraphs fields (entity_reference_revisions)

Created on 9 November 2020, about 4 years ago
Updated 15 May 2023, over 1 year ago

Problem/Motivation

When adding field states to a paragraphs field Iam getting a wsod and the error:

TypeError: Argument 1 passed to Drupal\Core\Field\WidgetBase::getWidgetState() must be of the type array, null given, called in /web/modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php on line 2212 in Drupal\Core\Field\WidgetBase::getWidgetState() (Zeile 484 in /web/core/lib/Drupal/Core/Field/WidgetBase.php)

It seems that the 'field_parents' array on the element gets unset in the process of setting the states. This is the function in ParagraphsWidget.php on line 2212 from the error message where $elements['#field_parents'] is NULL.

public function multipleElementValidate(array $elements, FormStateInterface $form_state, array $form) {
  $field_name = $this->fieldDefinition->getName();
  $widget_state = static::getWidgetState($elements['#field_parents'], $field_name, $form_state);

  if ($elements['#required'] && $widget_state['real_item_count'] < 1) {
    $form_state->setError($elements, $this->t('@name field is required.', ['@name' => $this->fieldDefinition->getLabel()]));
  }

  static::setWidgetState($elements['#field_parents'], $field_name, $form_state, $widget_state);
}

Steps to reproduce

  • Add a checkbox and a paragraphs field to a node.
  • Add a field state to the paragraphs: E.g. visible if checkbox is checked
  • Save the node
🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇩🇪Germany daveiano

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024