You are here

public function Workflow::delete in Workflow 8

Given a wid, delete the workflow and its data.

Overrides EntityBase::delete

File

src/Entity/Workflow.php, line 163

Class

Workflow
Workflow configuration entity to persistently store configuration.

Namespace

Drupal\workflow\Entity

Code

public function delete() {
  if (!$this
    ->isDeletable()) {
    $message = $this
      ->t('Workflow %workflow is not Deletable. Please delete the field where this workflow type is referred', [
      '%workflow' => $this
        ->label(),
    ]);
    $this
      ->messenger()
      ->addError($message);
    return;
  }
  else {

    // Delete associated state (also deletes any associated transitions).
    foreach ($this
      ->getStates(TRUE) as $state) {
      $state
        ->deactivate('');
      $state
        ->delete();
    }

    // Delete the workflow.
    parent::delete();
  }
}