Undefined index: #type in drupal_process_states() related to _token form element

Created on 3 December 2020, almost 5 years ago
Updated 2 September 2025, about 1 month ago

Problem/Motivation

I Just posted a module, https://www.drupal.org/project/ui_patterns_blocks that includes UI Patterns Settings integration. I'm running into an issue related to #states. Getting the following notice when bringing up a block configuration form that includes UI Patterns form elements:

Notice: Undefined index: #type in Drupal\Core\Form\FormHelper::processStates() (line 208 of core/lib/Drupal/Core/Form/FormHelper.php).

The source is this line in UI Patterns Settings SettingsFormBuilder::buildVariantsForm():

          $fieldset[$name . '_token']['#states']['invisible'][][$select_selector]['value'] = $variant->getName();

The issue is that $fieldset[$name . '_token'] is not present and so ends up as an array with only the '#states' key, which triggers this core bug: 🐛 Notice: Undefined index: #type in Drupal\Core\Form\FormHelper::processStates() Needs work .

What I'm not sure of is: (a) have I done something wrong/unexpected in my integration (i.e. is $fieldset[$name . '_token'] unexpectedly missing), or (b) should the code in SettingsFormBuilder::buildVariantsForm() be testing for $fieldset[$name . '_token'] before altering it.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Fixed

Version

2.0

Component

Code

Created by

🇨🇦Canada nedjo

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