function FormHelper::rewriteStatesSelector

Same name in other branches
  1. 9 core/lib/Drupal/Core/Form/FormHelper.php \Drupal\Core\Form\FormHelper::rewriteStatesSelector()
  2. 8.9.x core/lib/Drupal/Core/Form/FormHelper.php \Drupal\Core\Form\FormHelper::rewriteStatesSelector()
  3. 10 core/lib/Drupal/Core/Form/FormHelper.php \Drupal\Core\Form\FormHelper::rewriteStatesSelector()

Rewrites #states selectors in a render element.

When a structure of elements is being altered, their HTML selectors may change. In such cases calling this method will check if there are any states in element and its children, and rewrite selectors in those states.

Parameters

array $elements: A render array element having a #states property.

string $search: A partial or entire jQuery selector string to replace in #states.

string $replace: The string to replace all instances of $search with.

See also

self::processStates()

4 calls to FormHelper::rewriteStatesSelector()
EntityField::buildOptionsForm in core/modules/views/src/Plugin/views/field/EntityField.php
FieldBlock::formatterSettingsProcessCallback in core/modules/layout_builder/src/Plugin/Block/FieldBlock.php
Render API callback: builds the formatter settings elements.
FilterPluginBase::buildExposedFiltersGroupForm in core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
Build the form to let users create the group of exposed filters.
FormHelperTest::testRewriteStatesSelector in core/tests/Drupal/Tests/Core/Form/FormHelperTest.php
Tests rewriting the #states selectors.

File

core/lib/Drupal/Core/Form/FormHelper.php, line 31

Class

FormHelper
Provides helpers to operate on forms.

Namespace

Drupal\Core\Form

Code

public static function rewriteStatesSelector(array &$elements, $search, $replace) {
    if (!empty($elements['#states'])) {
        foreach ($elements['#states'] as $state => $ids) {
            static::processStatesArray($elements['#states'][$state], $search, $replace);
        }
    }
    foreach (Element::children($elements) as $key) {
        static::rewriteStatesSelector($elements[$key], $search, $replace);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.