public function WebformUiElementFormBase::buildDefaultValueForm in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_ui/src/Form/WebformUiElementFormBase.php \Drupal\webform_ui\Form\WebformUiElementFormBase::buildDefaultValueForm()
Build update default value form elements.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form.
1 call to WebformUiElementFormBase::buildDefaultValueForm()
- WebformUiElementFormBase::buildForm in modules/
webform_ui/ src/ Form/ WebformUiElementFormBase.php - Form constructor.
File
- modules/
webform_ui/ src/ Form/ WebformUiElementFormBase.php, line 678
Class
- WebformUiElementFormBase
- Provides a base class for webform element webforms.
Namespace
Drupal\webform_ui\FormCode
public function buildDefaultValueForm(array &$form, FormStateInterface $form_state) {
if (!isset($form['properties']['default']['default_value'])) {
return $form;
}
if ($element = $form_state
->get('default_value_element')) {
// Display the default value element.
$element['#webform_key'] = $this
->getWebform()
->id();
// Initialize the element.
$this->elementManager
->initializeElement($element);
// Build the element.
$this->elementManager
->buildElement($element, $form, $form_state);
$form['default'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Default value'),
];
$form['default']['default_value'] = $element;
// Hide properties using CSS.
// Using #access: FALSE is causing all properties to be lost.
$form['properties']['#type'] = 'container';
$form['properties']['#attributes']['style'] = 'display: none';
// Disable client-side validation.
$form['#attributes']['novalidate'] = TRUE;
// Replace 'Save' button with 'Update default value'.
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Update default value'),
'#attributes' => [
'data-hash' => 'webform-tab--advanced',
],
'#validate' => [
'::validateDefaultValue',
],
'#submit' => [
'::getDefaultValue',
],
'#button_type' => 'primary',
];
// Remove 'Save + Add element'.
unset($form['actions']['save_add_element']);
if ($this
->isAjax()) {
$form['actions']['submit']['#ajax'] = [
'callback' => '::submitAjaxForm',
'event' => 'click',
];
}
}
else {
// Add 'Set default value' button.
$form['properties']['default']['actions'] = [
'#type' => 'container',
];
$form['properties']['default']['actions']['set_default_value'] = [
'#type' => 'submit',
'#value' => $this
->t('Set default value'),
'#submit' => [
'::setDefaultValue',
],
'#attributes' => [
'formnovalidate' => 'formnovalidate',
],
'#_validate_form' => TRUE,
];
if ($this
->isAjax()) {
$form['properties']['default']['actions']['set_default_value']['#ajax'] = [
'callback' => '::submitAjaxForm',
'event' => 'click',
];
}
$form['#attached']['library'][] = 'webform/webform.form';
}
return $form;
}