Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By yched on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
The field_form_set_state() / field_form_get_state() functions were used in D7, mostly by field widgets, to safely place and retrieve data in $form_state without clashing with other fields in the form or other embedded subforms.
In D8, those have been moved to static getWidgetState() / setWidgetState() methods on WidgetBaseInterface.
Example
Drupal 7:
$state = field_form_get_state($parents, $field_name, $langcode, $form_state);
$state['foo'] = 'bar';
field_form_set_state($parents, $field_name, $langcode, $form_state, $state);
Drupal 8:
$state = \Drupal\Core\Field\WidgetBase::getWidgetState($parents, $field_name, $form_state);
// (or static::getWidgetState if the code lives in a widget class)
$state['foo'] = 'bar';
\Drupal\Core\Field\WidgetBase::getWidgetState($parents, $field_name, $form_state, $state);
// (or static::setWidgetState if the code lives in a widget class)
Impacts:
Module developers
Comments
Typo with set_state Drupal 8
Typo:
\Drupal\Core\Field\WidgetBase::getWidgetState($parents, $field_name, $form_state, $state);
Must be:
\Drupal\Core\Field\WidgetBase::setWidgetState($parents, $field_name, $form_state, $state);