public static function WebformFormHelper::processStates in Webform 8.5
Same name and namespace in other branches
- 6.x src/Utility/WebformFormHelper.php \Drupal\webform\Utility\WebformFormHelper::processStates()
Adds JavaScript to change the state of an element based on another element.
Parameters
array $elements: A renderable array element having a #states property as described above.
string $key: The element property to add the states attribute to.
See also
\Drupal\Core\Form\FormHelper::processStates
2 calls to WebformFormHelper::processStates()
- WebformComputedBase::processWebformComputed in src/
Element/ WebformComputedBase.php - Processes a Webform computed token element.
- webform_process_states in ./
webform.module - Adds JavaScript to change the state of an element based on another element.
File
- src/
Utility/ WebformFormHelper.php, line 24
Class
- WebformFormHelper
- Helper class webform based methods.
Namespace
Drupal\webform\UtilityCode
public static function processStates(array &$elements, $key = '#attributes') {
if (empty($elements['#states'])) {
return;
}
$elements['#attached']['library'][] = 'core/drupal.states';
$elements[$key]['data-drupal-states'] = Json::encode($elements['#states']);
// Make sure to include target class for this container.
if (empty($elements[$key]['class']) || !WebformArrayHelper::inArray([
'js-form-item',
'js-form-submit',
'js-form-wrapper',
], $elements[$key]['class'])) {
$elements[$key]['class'][] = 'js-form-item';
}
}