public static function FormHelper::rewriteStatesSelector in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Form/FormHelper.php \Drupal\Core\Form\FormHelper::rewriteStatesSelector()
- 9 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
2 calls to FormHelper::rewriteStatesSelector()
- 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\FormCode
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);
}
}