You are here

public function WebformUiElementFormBase::setDefaultValue in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_ui/src/Form/WebformUiElementFormBase.php \Drupal\webform_ui\Form\WebformUiElementFormBase::setDefaultValue()

Set default value to be updated.

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

modules/webform_ui/src/Form/WebformUiElementFormBase.php, line 791

Class

WebformUiElementFormBase
Provides a base class for webform element webforms.

Namespace

Drupal\webform_ui\Form

Code

public function setDefaultValue(array &$form, FormStateInterface $form_state) {
  $element_plugin = $this
    ->getWebformElementPlugin();
  $subform_state = SubformState::createForSubform($form['properties'], $form, $form_state);
  $properties = $element_plugin
    ->getConfigurationFormProperties($form, $subform_state);
  if (isset($properties['#default_value'])) {

    // @see \Drupal\webform\Plugin\WebformElementBase::getConfigurationFormProperty
    if ($element_plugin
      ->hasMultipleValues($properties) && is_string($properties['#default_value'])) {
      $properties['#default_value'] = preg_split('/\\s*,\\s*/', $properties['#default_value']);
    }
  }
  $form_state
    ->set('default_value_element', $properties);
  $form_state
    ->setRebuild(TRUE);
}