You are here

public function ConfirmAction::buildForm in Views Bulk Operations (VBO) 8

Same name and namespace in other branches
  1. 8.3 src/Form/ConfirmAction.php \Drupal\views_bulk_operations\Form\ConfirmAction::buildForm()
  2. 8.2 src/Form/ConfirmAction.php \Drupal\views_bulk_operations\Form\ConfirmAction::buildForm()
  3. 4.0.x src/Form/ConfirmAction.php \Drupal\views_bulk_operations\Form\ConfirmAction::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 FormInterface::buildForm

File

src/Form/ConfirmAction.php, line 81

Class

ConfirmAction
Default action execution confirmation form.

Namespace

Drupal\views_bulk_operations\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $view_id = NULL, $display_id = NULL) {
  $form_data = $this
    ->getFormData($view_id, $display_id);

  // TODO: display an error msg, redirect back.
  if (!isset($form_data['action_id'])) {
    return;
  }
  $form_state
    ->setStorage($form_data);
  if (!empty($form_data['entity_labels'])) {
    $form['list'] = [
      '#theme' => 'item_list',
      '#items' => $form_data['entity_labels'],
    ];
  }
  $form['#title'] = $this
    ->formatPlural($form_data['selected_count'], 'Are you sure you wish to perform "%action" action on 1 entity?', 'Are you sure you wish to perform "%action" action on %count entities?', [
    '%action' => $form_data['action_label'],
    '%count' => $form_data['selected_count'],
  ]);
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Execute action'),
    '#submit' => [
      [
        $this,
        'submitForm',
      ],
    ],
  ];
  return $form;
}