You are here

public function MaestroTemplateDeleteForm::submitForm in Maestro 3.x

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

The submit handler for the confirm form.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The form's form state.

Overrides EntityForm::submitForm

File

src/Form/MaestroTemplateDeleteForm.php, line 85

Class

MaestroTemplateDeleteForm
Class MaestroTemplateDeleteForm.

Namespace

Drupal\maestro\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Delete all open processes with this template.
  $query = \Drupal::entityQuery('maestro_process')
    ->condition('template_id', $this->entity->id);
  $entityIDs = $query
    ->execute();
  foreach ($entityIDs as $processID) {
    MaestroEngine::deleteProcess($processID);
  }

  // Delete the entity.
  $this->entity
    ->delete();

  // Set a message that the entity was deleted.
  \Drupal::messenger()
    ->addMessage(t('Template %label was deleted.', [
    '%label' => $this->entity
      ->label(),
  ]));

  // Redirect the user to the list controller when complete.
  $form_state
    ->setRedirect('entity.maestro_template.list');
}