You are here

public static function WebformElementStates::editSourceSubmit in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Element/WebformElementStates.php \Drupal\webform\Element\WebformElementStates::editSourceSubmit()

Form submission handler for editing source.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

File

src/Element/WebformElementStates.php, line 696

Class

WebformElementStates
Provides a webform element to edit an element's #states.

Namespace

Drupal\webform\Element

Code

public static function editSourceSubmit(array &$form, FormStateInterface $form_state) {

  // Get the webform states element by going up one level.
  $button = $form_state
    ->getTriggeringElement();
  $element =& NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -2));

  // Set edit source.
  $form_state
    ->set(static::getStorageKey($element, 'edit_source'), TRUE);

  // Convert states to editable string.
  $value = $element['#value'] ? Yaml::encode($element['#value']) : '';
  $form_state
    ->setValueForElement($element['states'], $value);
  NestedArray::setValue($form_state
    ->getUserInput(), $element['states']['#parents'], $value);

  // Rebuild the form.
  $form_state
    ->setRebuild();
}