Skip to content
Snippets Groups Projects
Commit 465a6059 authored by John Voskuilen's avatar John Voskuilen
Browse files

Issue #3440229: Creation state is not deleted when deleting a Workflow type

parent 7c5bc454
Branches
Tags
No related merge requests found
Pipeline #143968 passed with warnings
...@@ -138,7 +138,7 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface { ...@@ -138,7 +138,7 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
$status = parent::save(); $status = parent::save();
// Make sure a Creation state exists, when saving a Workflow. // Make sure a Creation state exists, when saving a Workflow.
if ($status == SAVED_NEW) { if ($status == SAVED_NEW) {
$this->getCreationState(); $this->createCreationState();
} }
return $status; return $status;
...@@ -153,7 +153,6 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface { ...@@ -153,7 +153,6 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
// Better performance, together with Annotation static_cache = TRUE. // Better performance, together with Annotation static_cache = TRUE.
// Load the states, and set the creation state. // Load the states, and set the creation state.
$workflow->getStates(); $workflow->getStates();
$workflow->getCreationState();
} }
} }
...@@ -239,6 +238,21 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface { ...@@ -239,6 +238,21 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
return $this->id(); return $this->id();
} }
/**
* {@inheritdoc}
*/
public function createCreationState() {
if (\Drupal::isConfigSyncing()) {
// Do not create the default state while configuration are importing.
}
elseif (!$this->creation_state) {
$state = $this->createState(WORKFLOW_CREATION_STATE_NAME);
$this->creation_state = $state;
$this->creation_sid = $state->id();
}
return $this->creation_state;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -274,17 +288,8 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface { ...@@ -274,17 +288,8 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
} }
} }
} }
// If not found, create it.
// Then, create it. $this->createCreationState();
if (\Drupal::isConfigSyncing()) {
// Do not create the default state while configuration are importing.
}
elseif (!$this->creation_state) {
$state = $this->createState(WORKFLOW_CREATION_STATE_NAME);
$this->creation_state = $state;
$this->creation_sid = $state->id();
}
return $this->creation_state; return $this->creation_state;
} }
...@@ -293,8 +298,7 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface { ...@@ -293,8 +298,7 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
*/ */
public function getCreationSid() { public function getCreationSid() {
if (!$this->creation_sid) { if (!$this->creation_sid) {
$state = $this->getCreationState(); $this->getCreationState();
return $state->id();
} }
return $this->creation_sid; return $this->creation_sid;
} }
......
...@@ -41,6 +41,14 @@ interface WorkflowInterface extends EntityInterface { ...@@ -41,6 +41,14 @@ interface WorkflowInterface extends EntityInterface {
*/ */
public function isDeletable(); public function isDeletable();
/**
* Creates the initial state for a new Workflow.
*
* @return \Drupal\workflow\Entity\WorkflowState
* The initial state.
*/
public function createCreationState();
/** /**
* Create a new state for this workflow. * Create a new state for this workflow.
* *
...@@ -61,7 +69,7 @@ interface WorkflowInterface extends EntityInterface { ...@@ -61,7 +69,7 @@ interface WorkflowInterface extends EntityInterface {
* Gets the initial state for a newly created entity. * Gets the initial state for a newly created entity.
* *
* @return \Drupal\workflow\Entity\WorkflowState * @return \Drupal\workflow\Entity\WorkflowState
* The intial state. * The initial state.
*/ */
public function getCreationState(); public function getCreationState();
......
...@@ -133,21 +133,20 @@ class WorkflowConfigTransitionRoleForm extends WorkflowConfigTransitionFormBase ...@@ -133,21 +133,20 @@ class WorkflowConfigTransitionRoleForm extends WorkflowConfigTransitionFormBase
} }
// Make sure 'author' is checked for (creation) -> [something]. // Make sure 'author' is checked for (creation) -> [something].
$creation_state_id = $this->workflow->getCreationState()->id(); $creation_state = $this->workflow->getCreationState();
$author_has_permission = FALSE; $author_has_permission = FALSE;
foreach ($form_state->getValue($this->entitiesKey) as $from_sid => $to_data) { foreach ($form_state->getValue($this->entitiesKey) as $from_sid => $to_data) {
foreach ($to_data as $to_sid => $transition_data) { foreach ($to_data as $to_sid => $transition_data) {
if (empty($transition_data['roles'][WORKFLOW_ROLE_AUTHOR_RID])) { if (empty($transition_data['roles'][WORKFLOW_ROLE_AUTHOR_RID])) {
continue; continue;
} }
if ($from_sid == $creation_state_id && $from_sid != $to_sid) { if ($from_sid == $creation_state->id() && $from_sid != $to_sid) {
$author_has_permission = TRUE; $author_has_permission = TRUE;
break; break;
} }
} }
} }
if (!$author_has_permission) { if (!$author_has_permission) {
$creation_state = $this->workflow->getCreationState();
$form_state->setErrorByName('id', $this->t('Please give the author permission to go from %creation to at least one state!', $form_state->setErrorByName('id', $this->t('Please give the author permission to go from %creation to at least one state!',
['%creation' => $creation_state->label()])); ['%creation' => $creation_state->label()]));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment