You are here

public function ActionWebformHandler::buildConfigurationForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformHandler/ActionWebformHandler.php \Drupal\webform\Plugin\WebformHandler\ActionWebformHandler::buildConfigurationForm()

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides WebformHandlerBase::buildConfigurationForm

File

src/Plugin/WebformHandler/ActionWebformHandler.php, line 99

Class

ActionWebformHandler
Webform submission action handler.

Namespace

Drupal\webform\Plugin\WebformHandler

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $results_disabled = $this
    ->getWebform()
    ->getSetting('results_disabled');
  $form['trigger'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Trigger'),
  ];
  $form['trigger']['states'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Execute'),
    '#options' => [
      WebformSubmissionInterface::STATE_DRAFT_CREATED => $this
        ->t('…when <b>draft is created</b>.'),
      WebformSubmissionInterface::STATE_DRAFT_UPDATED => $this
        ->t('…when <b>draft is updated</b>.'),
      WebformSubmissionInterface::STATE_CONVERTED => $this
        ->t('…when anonymous <b>submission is converted</b> to authenticated.'),
      WebformSubmissionInterface::STATE_COMPLETED => $this
        ->t('…when <b>submission is completed</b>.'),
      WebformSubmissionInterface::STATE_UPDATED => $this
        ->t('…when <b>submission is updated</b>.'),
    ],
    '#required' => TRUE,
    '#access' => $results_disabled ? FALSE : TRUE,
    '#default_value' => $results_disabled ? [
      WebformSubmissionInterface::STATE_COMPLETED,
    ] : $this->configuration['states'],
  ];
  $form['actions'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Actions'),
  ];
  $form['actions']['sticky'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Change status'),
    '#empty_option' => $this
      ->t('- None -'),
    '#options' => [
      '1' => $this
        ->t('Flag/Star'),
      '0' => $this
        ->t('Unflag/Unstar'),
    ],
    '#default_value' => $this->configuration['sticky'] === NULL ? '' : ($this->configuration['sticky'] ? '1' : '0'),
  ];
  $form['actions']['locked'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Change lock'),
    '#description' => $this
      ->t('Webform submissions can only be unlocked programatically.'),
    '#empty_option' => $this
      ->t('- None -'),
    '#options' => [
      '' => '',
      '1' => $this
        ->t('Lock'),
      '0' => $this
        ->t('Unlock'),
    ],
    '#default_value' => $this->configuration['locked'] === NULL ? '' : ($this->configuration['locked'] ? '1' : '0'),
  ];
  $form['actions']['notes'] = [
    '#type' => 'webform_codemirror',
    '#mode' => 'text',
    '#title' => $this
      ->t('Append the below text to notes (Plain text)'),
    '#default_value' => $this->configuration['notes'],
  ];
  $form['actions']['message'] = [
    '#type' => 'webform_html_editor',
    '#title' => $this
      ->t('Display message'),
    '#default_value' => $this->configuration['message'],
  ];
  $form['actions']['message_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Display message type'),
    '#options' => [
      'status' => $this
        ->t('Status'),
      'error' => $this
        ->t('Error'),
      'warning' => $this
        ->t('Warning'),
      'info' => $this
        ->t('Info'),
    ],
    '#default_value' => $this->configuration['message_type'],
  ];
  $form['actions']['data'] = [
    '#type' => 'webform_codemirror',
    '#mode' => 'yaml',
    '#title' => $this
      ->t('Update the below submission data. (YAML)'),
    '#default_value' => $this->configuration['data'],
  ];
  $elements_rows = [];
  $elements = $this
    ->getWebform()
    ->getElementsInitializedFlattenedAndHasValue();
  foreach ($elements as $element_key => $element) {
    $elements_rows[] = [
      $element_key,
      isset($element['#title']) ? $element['#title'] : '',
    ];
  }
  $form['actions']['elements'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Available element keys'),
    'element_keys' => [
      '#type' => 'table',
      '#header' => [
        $this
          ->t('Element key'),
        $this
          ->t('Element title'),
      ],
      '#rows' => $elements_rows,
    ],
  ];
  $form['actions']['token_tree_link'] = $this
    ->buildTokenTreeElement();

  // Development.
  $form['development'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Development settings'),
  ];
  $form['development']['debug'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable debugging'),
    '#description' => $this
      ->t('If checked, trigger actions will be displayed onscreen to all users.'),
    '#return_value' => TRUE,
    '#default_value' => $this->configuration['debug'],
  ];
  $this
    ->elementTokenValidate($form);
  return $this
    ->setSettingsParents($form);
}