You are here

public function WebformDeleteMultipleFormBase::buildForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Form/WebformDeleteMultipleFormBase.php \Drupal\webform\Form\WebformDeleteMultipleFormBase::buildForm()

Form constructor.

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 structure.

Overrides DeleteMultipleForm::buildForm

File

src/Form/WebformDeleteMultipleFormBase.php, line 21

Class

WebformDeleteMultipleFormBase
Provides an entities deletion confirmation form.

Namespace

Drupal\webform\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL) {

  // Issue #2582295: Confirmation cancel links are incorrect if installed in
  // a subdirectory
  // Work-around: Remove subdirectory from destination before generating
  // actions.
  $request = $this
    ->getRequest();
  $destination = $request->query
    ->get('destination');
  if ($destination) {

    // Remove subdirectory from destination.
    $update_destination = preg_replace('/^' . preg_quote(base_path(), '/') . '/', '/', $destination);
    $request->query
      ->set('destination', $update_destination);
    $form = parent::buildForm($form, $form_state, $entity_type_id);
    $request->query
      ->set('destination', $destination);
  }
  else {
    $form = parent::buildForm($form, $form_state, $entity_type_id);
  }

  // Exit if redirect.
  if ($form instanceof RedirectResponse) {
    return $form;
  }
  $form['message'] = $this
    ->getWarning();
  $form['entities'] += [
    '#prefix' => $this
      ->formatPlural(count($this->selection), 'The below @item will be deleted.', 'The below @items will be deleted.', [
      '@item' => $this->entityType
        ->getSingularLabel(),
      '@items' => $this->entityType
        ->getPluralLabel(),
    ]),
    '#suffix' => '<p><hr/></p>',
  ];
  $form['description'] = $this
    ->getDescription();
  $form['hr'] = [
    '#markup' => '<p><hr/></p>',
  ];
  $form['confirm_input'] = $this
    ->getConfirmInput();
  return $form;
}