X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fworkflows%2Fsrc%2FForm%2FWorkflowStateDeleteForm.php;h=bfca31e97ef8f6919c9808ffea5adf89b9a746bd;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=c60045ca23a57487f38cea856e428fc0c46c010e;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/workflows/src/Form/WorkflowStateDeleteForm.php b/web/core/modules/workflows/src/Form/WorkflowStateDeleteForm.php index c60045ca2..bfca31e97 100644 --- a/web/core/modules/workflows/src/Form/WorkflowStateDeleteForm.php +++ b/web/core/modules/workflows/src/Form/WorkflowStateDeleteForm.php @@ -37,7 +37,7 @@ class WorkflowStateDeleteForm extends ConfirmFormBase { * {@inheritdoc} */ public function getQuestion() { - return $this->t('Are you sure you want to delete %state from %workflow?', ['%state' => $this->workflow->getState($this->stateId)->label(), '%workflow' => $this->workflow->label()]); + return $this->t('Are you sure you want to delete %state from %workflow?', ['%state' => $this->workflow->getTypePlugin()->getState($this->stateId)->label(), '%workflow' => $this->workflow->label()]); } /** @@ -70,11 +70,18 @@ class WorkflowStateDeleteForm extends ConfirmFormBase { * The form structure. */ public function buildForm(array $form, FormStateInterface $form_state, WorkflowInterface $workflow = NULL, $workflow_state = NULL) { - if (!$workflow->hasState($workflow_state)) { + if (!$workflow->getTypePlugin()->hasState($workflow_state)) { throw new NotFoundHttpException(); } $this->workflow = $workflow; $this->stateId = $workflow_state; + + if ($this->workflow->getTypePlugin()->workflowStateHasData($this->workflow, $this->workflow->getTypePlugin()->getState($this->stateId))) { + $form['#title'] = $this->getQuestion(); + $form['description'] = ['#markup' => $this->t('This workflow state is in use. You cannot remove this workflow state until you have removed all content using it.')]; + return $form; + } + return parent::buildForm($form, $form_state); } @@ -83,10 +90,11 @@ class WorkflowStateDeleteForm extends ConfirmFormBase { */ public function submitForm(array &$form, FormStateInterface $form_state) { - $workflow_label = $this->workflow->getState($this->stateId)->label(); + $workflow_label = $this->workflow->getTypePlugin()->getState($this->stateId)->label(); $this->workflow - ->deleteState($this->stateId) - ->save(); + ->getTypePlugin() + ->deleteState($this->stateId); + $this->workflow->save(); drupal_set_message($this->t( 'State %label deleted.',