You are here

public function WebformUiElementFormBase::getDefaultValue 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::getDefaultValue()

Get updated default value for an element.

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 759

Class

WebformUiElementFormBase
Provides a base class for webform element webforms.

Namespace

Drupal\webform_ui\Form

Code

public function getDefaultValue(array &$form, FormStateInterface $form_state) {
  $default_value = $form_state
    ->getValue('default_value');
  $form_state
    ->unsetValue('default_value');

  // Convert composite or multiple default value array to string.
  // @see \Drupal\webform\Plugin\WebformElementBase::setConfigurationFormDefaultValue
  $element_plugin = $this
    ->getWebformElementPlugin();
  if (is_array($default_value)) {
    if ($element_plugin
      ->isComposite()) {
      $default_value = WebformYaml::encode($default_value);
    }
    else {
      $default_value = implode(', ', $default_value);
    }
  }
  $form_state
    ->setValueForElement($form['properties']['default']['default_value'], $default_value);
  NestedArray::setValue($form_state
    ->getUserInput(), [
    'properties',
    'default_value',
  ], $default_value);
  $form_state
    ->set('active_tab', 'advanced');
  $form_state
    ->set('default_value_element', NULL);
  $form_state
    ->setRebuild(TRUE);
}