You are here

public function WebformMessage::form in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElement/WebformMessage.php \Drupal\webform\Plugin\WebformElement\WebformMessage::form()

Gets the actual configuration webform array to be built.

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 An associative array contain the element's configuration webform without any default values.

Overrides WebformMarkupBase::form

File

src/Plugin/WebformElement/WebformMessage.php, line 87

Class

WebformMessage
Provides a 'webform_message' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['markup']['#title'] = $this
    ->t('Message settings');
  $form['markup']['message_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Message type'),
    '#options' => [
      'status' => $this
        ->t('Status'),
      'error' => $this
        ->t('Error'),
      'warning' => $this
        ->t('Warning'),
      'info' => $this
        ->t('Info'),
    ],
    '#required' => TRUE,
  ];
  $form['markup']['message_message'] = [
    '#type' => 'webform_html_editor',
    '#title' => $this
      ->t('Message content'),
    '#required' => TRUE,
  ];
  $form['markup']['message_close'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow users to close the message'),
    '#return_value' => TRUE,
  ];
  $form['markup']['message_close_effect'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Message close effect'),
    '#options' => [
      'hide' => $this
        ->t('Hide'),
      'slide' => $this
        ->t('Slide'),
      'fade' => $this
        ->t('Fade'),
    ],
    '#states' => [
      'visible' => [
        ':input[name="properties[message_close]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['markup']['message_storage'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Message storage'),
    '#options' => [
      WebformMessageElement::STORAGE_NONE => $this
        ->t('None -- Message state is never stored.'),
      WebformMessageElement::STORAGE_SESSION => $this
        ->t('Session storage -- Message state is reset after the browser is closed.'),
      WebformMessageElement::STORAGE_LOCAL => $this
        ->t('Local storage -- Message state persists after the browser is closed.'),
      WebformMessageElement::STORAGE_USER => $this
        ->t("User data -- Message state is saved to the current user's data. (Applies to authenticated users only)"),
      WebformMessageElement::STORAGE_STATE => $this
        ->t("State API -- Message state is saved to the site's system state. (Applies to authenticated users only)"),
    ],
    '#options_description_display' => 'help',
    '#states' => [
      'visible' => [
        ':input[name="properties[message_close]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['markup']['message_id'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Message ID'),
    '#description' => $this
      ->t("Unique ID used to store the message's closed state. Please enter only lower-case letters, numbers, dashes, and underscores.") . '<br /><br />' . $this
      ->t('Defaults to: %value', [
      '%value' => '[webform:id]--[element:key]',
    ]),
    '#pattern' => '/^[a-z0-9-_]+$/',
    '#states' => [
      'visible' => [
        ':input[name="properties[message_close]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  return $form;
}