You are here

public function DashboardDeleteForm::submitForm in Draggable dashboard 8

Same name and namespace in other branches
  1. 8.2 src/Form/DashboardDeleteForm.php \Drupal\draggable_dashboard\Form\DashboardDeleteForm::submitForm()

Form submission handler.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/DashboardDeleteForm.php, line 100

Class

DashboardDeleteForm
Provides a form to delete Dashboard Form.

Namespace

Drupal\draggable_dashboard\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $blocks = json_decode($this->dashboard
    ->get('blocks'), TRUE);
  foreach ($blocks as $relation) {
    $block = Block::load($relation['bid']);
    if ($block) {
      $block
        ->delete();
    }
  }
  $this
    ->logger('user')
    ->notice('Deleted `%title`', [
    '%title' => $this->dashboard
      ->get('title'),
  ]);
  $this
    ->messenger()
    ->addMessage($this
    ->t('The dashboard `%title` was deleted.', [
    '%title' => $this->dashboard
      ->get('title'),
  ]));

  // Delete dashboard.
  $this->dashboard
    ->delete();

  // Invalidate block list cache.
  $this->blockManager
    ->clearCachedDefinitions();

  // Redirect to dashboard overview page.
  $form_state
    ->setRedirectUrl($this
    ->getCancelUrl());
}