MaestroTemplateDeleteForm.php in Maestro 3.x
File
src/Form/MaestroTemplateDeleteForm.php
View source
<?php
namespace Drupal\maestro\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
use Drupal\maestro\Engine\MaestroEngine;
class MaestroTemplateDeleteForm extends EntityConfirmFormBase {
public function getDescription() {
$count_warning = '';
$query = \Drupal::entityQuery('maestro_process')
->condition('template_id', $this->entity->id);
$res = $query
->execute();
$count = count($res);
if ($count > 1) {
return $this
->t('<strong style="color: red; font-size: 1.2em;">Warning!</strong> There are %count open processes attached to this Template.
Deleting this process will remove all associated Maestro data. This action cannot be undone.', [
'%count' => $count,
]);
}
elseif ($count == 1) {
return $this
->t('<strong style="color: red; font-size: 1.2em;">Warning!</strong> There is %count open process attached to this Template.
Deleting this process will remove all associated Maestro data. This action cannot be undone.', [
'%count' => $count,
]);
}
return $this
->t('This action cannot be undone.');
}
public function getQuestion() {
return $this
->t('Are you sure you want to delete Template %label?', [
'%label' => $this->entity
->label(),
]);
}
public function getConfirmText() {
return $this
->t('Delete Template');
}
public function getCancelUrl() {
return new Url('entity.maestro_template.list');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$query = \Drupal::entityQuery('maestro_process')
->condition('template_id', $this->entity->id);
$entityIDs = $query
->execute();
foreach ($entityIDs as $processID) {
MaestroEngine::deleteProcess($processID);
}
$this->entity
->delete();
\Drupal::messenger()
->addMessage(t('Template %label was deleted.', [
'%label' => $this->entity
->label(),
]));
$form_state
->setRedirect('entity.maestro_template.list');
}
}