You are here

function yamlform_process_states in YAML Form 8

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_process_states()

1 call to yamlform_process_states()
YamlFormOtherBase::processYamlFormOther in src/Element/YamlFormOtherBase.php
Processes an 'other' element.

File

./yamlform.module, line 556
Enables the creation of forms and questionnaires.

Code

function yamlform_process_states(&$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']) || !YamlFormArrayHelper::inArray([
    'js-form-item',
    'js-form-submit',
    'js-form-wrapper',
  ], $elements[$key]['class'])) {
    $elements[$key]['class'][] = 'js-form-item';
  }
}