You are here

public static function WebformFormHelper::processStates in Webform 6.x

Same name and namespace in other branches
  1. 8.5 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

9 calls to WebformFormHelper::processStates()
WebformCompositeFormElementTrait::preRenderWebformCompositeFormElement in src/Element/WebformCompositeFormElementTrait.php
Adds form element theming to an element if its title or description is set.
WebformComputedBase::processWebformComputed in src/Element/WebformComputedBase.php
Processes a Webform computed token element.
WebformElementOptions::processWebformElementOptions in src/Element/WebformElementOptions.php
Processes a webform element options element.
WebformHtmlEditor::processWebformHtmlEditor in src/Element/WebformHtmlEditor.php
Prepares a #type 'webform_html_editor' render element for input.html.twig.
WebformImageSelectElementImages::processWebformImageSelectElementImages in modules/webform_image_select/src/Element/WebformImageSelectElementImages.php
Processes a webform element image select images element.

... See full list

File

src/Utility/WebformFormHelper.php, line 24

Class

WebformFormHelper
Helper class webform based methods.

Namespace

Drupal\webform\Utility

Code

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';
  }
}