You are here

public function BlockDeleteForm::buildForm in Context 8

Same name and namespace in other branches
  1. 8.4 src/Reaction/Blocks/Form/BlockDeleteForm.php \Drupal\context\Reaction\Blocks\Form\BlockDeleteForm::buildForm()
  2. 8.0 src/Reaction/Blocks/Form/BlockDeleteForm.php \Drupal\context\Reaction\Blocks\Form\BlockDeleteForm::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 ConfirmFormBase::buildForm

File

src/Reaction/Blocks/Form/BlockDeleteForm.php, line 93

Class

BlockDeleteForm

Namespace

Drupal\context\Reaction\Blocks\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, ContextInterface $context = NULL, $block_id = NULL) {
  $this->context = $context;
  $this->reaction = $this->context
    ->getReaction('blocks');
  $this->block = $this->reaction
    ->getBlock($block_id);
  $form = parent::buildForm($form, $form_state);

  // Remove the cancel button if this is an AJAX request since Drupals built
  // in modal dialogues does not handle buttons that are not a primary
  // button very well.
  if ($this
    ->getRequest()
    ->isXmlHttpRequest()) {
    unset($form['actions']['cancel']);
  }

  // Submit the form with AJAX if possible.
  $form['actions']['submit']['#ajax'] = [
    'callback' => '::submitFormAjax',
  ];
  return $form;
}