WorkflowTransitionDeleteForm.php in Drupal 10
File
core/modules/workflows/src/Form/WorkflowTransitionDeleteForm.php
View source
<?php
namespace Drupal\workflows\Form;
use Drupal\workflows\WorkflowInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class WorkflowTransitionDeleteForm extends ConfirmFormBase {
protected $workflow;
protected $transition;
protected $transitionId;
public function getFormId() {
return 'workflow_transition_delete_form';
}
public function getQuestion() {
return $this
->t('Are you sure you want to delete %transition from %workflow?', [
'%transition' => $this->transition
->label(),
'%workflow' => $this->workflow
->label(),
]);
}
public function getCancelUrl() {
return $this->workflow
->toUrl();
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function buildForm(array $form, FormStateInterface $form_state, WorkflowInterface $workflow = NULL, $workflow_transition = NULL) {
try {
$this->transition = $workflow
->getTypePlugin()
->getTransition($workflow_transition);
} catch (\InvalidArgumentException $e) {
throw new NotFoundHttpException();
}
$this->workflow = $workflow;
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->workflow
->getTypePlugin()
->deleteTransition($this->transition
->id());
$this->workflow
->save();
$this
->messenger()
->addStatus($this
->t('%transition transition deleted.', [
'%transition' => $this->transition
->label(),
]));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}