You are here

public function Webform::buildConfigurationForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/Condition/Webform.php \Drupal\webform\Plugin\Condition\Webform::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 ConditionPluginBase::buildConfigurationForm

File

src/Plugin/Condition/Webform.php, line 49

Class

Webform
Provides a 'Webform' condition.

Namespace

Drupal\webform\Plugin\Condition

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $options = [];
  $webforms = $this
    ->getWebformStorage()
    ->loadMultiple();
  foreach ($webforms as $webform) {
    $options[$webform
      ->id()] = $webform
      ->label();
  }
  $form['webforms'] = [
    '#title' => $this
      ->t('Webform'),
    '#description' => $this
      ->t('Select which webforms this block should be displayed on.'),
    '#type' => 'select',
    '#options' => $options,
    '#multiple' => $options,
    '#select2' => TRUE,
    '#default_value' => $this->configuration['webforms'],
  ];
  WebformElementHelper::process($form['webforms']);
  if (empty($this->configuration['context_mapping'])) {
    $form['message'] = [
      '#type' => 'webform_message',
      '#message_message' => $this
        ->t('Please make sure to select which entities should be used to determine the current webform.'),
      '#message_type' => 'warning',
    ];
  }
  $form = parent::buildConfigurationForm($form, $form_state);

  // Add helpful descriptions to context mapping.
  $form['context_mapping']['webform']['#description'] = $this
    ->t("Select 'Webform from URL' to display this block, when the current request's path contains the selected webform.");
  $form['context_mapping']['webform_submission']['#title'] = $this
    ->t('Select a @context value:', [
    '@context' => $this
      ->t('webform submission'),
  ]);
  $form['context_mapping']['webform_submission']['#description'] = $this
    ->t("Select 'Webform submission from URL' to display this block, when the current request's path contains a webform submission that was created from the selected webform.");
  $form['context_mapping']['node']['#description'] = $this
    ->t("Select 'Node from URL' to display this block, when the current request's path contains a node that references the selected webform using a dedicated webform field or node.");

  // Attached library to summarize configuration settings.
  $form['#attached']['library'][] = 'webform/webform.block';
  return $form;
}