Unverified Commit 1ab1078b authored by larowlan's avatar larowlan
Browse files

Issue #2896725 by Sam152, Wim Leers: Entirely remove the concept of...

Issue #2896725 by Sam152, Wim Leers: Entirely remove the concept of WorkflowType(Interface|Base)::initializeWorkflow()
parent 0d6d6736
......@@ -84,8 +84,6 @@ public function form(array $form, FormStateInterface $form_state) {
public function save(array $form, FormStateInterface $form_state) {
/* @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $this->entity;
// Initialize the workflow using the selected type plugin.
$workflow = $workflow->getTypePlugin()->initializeWorkflow($workflow);
$return = $workflow->save();
if (empty($workflow->getTypePlugin()->getStates())) {
drupal_set_message($this->t('Created the %label Workflow. In order for the workflow to be enabled there needs to be at least one state.', [
......
......@@ -37,13 +37,6 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
$this->setConfiguration($configuration);
}
/**
* {@inheritdoc}
*/
public function initializeWorkflow(WorkflowInterface $workflow) {
return $workflow;
}
/**
* {@inheritdoc}
*/
......
......@@ -17,21 +17,6 @@
*/
interface WorkflowTypeInterface extends PluginInspectionInterface, DerivativeInspectionInterface, ConfigurablePluginInterface {
/**
* Initializes a workflow.
*
* Used to create required states and default transitions.
*
* @param \Drupal\workflows\WorkflowInterface $workflow
* The workflow to initialize.
*
* @return \Drupal\workflows\WorkflowInterface
* The initialized workflow.
*
* @see \Drupal\workflows\Form\WorkflowAddForm::save()
*/
public function initializeWorkflow(WorkflowInterface $workflow);
/**
* Gets the label for the workflow type.
*
......
......@@ -4,7 +4,6 @@
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\workflows\Plugin\WorkflowTypeBase;
use Drupal\workflows\WorkflowInterface;
/**
* Test workflow type.
......@@ -25,14 +24,29 @@ class RequiredStateTestType extends WorkflowTypeBase {
/**
* {@inheritdoc}
*/
public function initializeWorkflow(WorkflowInterface $workflow) {
$workflow
->getTypePlugin()
->addState('fresh', $this->t('Fresh'))
->setStateWeight('fresh', -5)
->addState('rotten', $this->t('Rotten'))
->addTransition('rot', $this->t('Rot'), ['fresh'], 'rotten');
return $workflow;
public function defaultConfiguration() {
return [
'states' => [
'fresh' => [
'label' => 'Fresh',
'weight' => 0,
],
'rotten' => [
'label' => 'Rotten',
'weight' => 1,
],
],
'transitions' => [
'rot' => [
'label' => 'Rot',
'to' => 'rotten',
'weight' => 0,
'from' => [
'fresh',
],
],
],
];
}
}
......@@ -254,9 +254,8 @@ public function testWorkflowCreation() {
$this->assertSession()->pageTextContains('There is no Workflow yet.');
$this->assertNull($workflow_storage->loadUnchanged('test'), 'The test workflow has been deleted');
// Ensure that workflow types that implement
// \Drupal\workflows\WorkflowTypeInterface::initializeWorkflow() are
// initialized correctly.
// Ensure that workflow types with default configuration are initialized
// correctly.
$this->drupalGet('admin/config/workflow/workflows');
$this->clickLink('Add workflow');
$this->submitForm(['label' => 'Test 2', 'id' => 'test2', 'workflow_type' => 'workflow_type_required_state_test'], 'Save');
......
......@@ -22,7 +22,6 @@ class RequiredStatesTest extends KernelTestBase {
/**
* @covers ::getRequiredStates
* @covers ::initializeWorkflow
* @covers ::__construct
*/
public function testGetRequiredStates() {
......@@ -30,8 +29,6 @@ public function testGetRequiredStates() {
'id' => 'test',
'type' => 'workflow_type_required_state_test',
], 'workflow');
/** @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $workflow->getTypePlugin()->initializeWorkflow($workflow);
$workflow->save();
$this->assertEquals(['fresh', 'rotten'], $workflow->getTypePlugin()
->getRequiredStates());
......@@ -50,8 +47,6 @@ public function testDeleteRequiredStateAPI() {
'id' => 'test',
'type' => 'workflow_type_required_state_test',
], 'workflow');
/** @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $workflow->getTypePlugin()->initializeWorkflow($workflow);
$workflow->save();
// Ensure that required states can't be deleted.
$this->setExpectedException(RequiredStateMissingException::class, "Required State Type Test' requires states with the ID 'fresh' in workflow 'test'");
......@@ -66,6 +61,9 @@ public function testNoStatesRequiredStateAPI() {
$workflow = new Workflow([
'id' => 'test',
'type' => 'workflow_type_required_state_test',
'type_settings' => [
'states' => [],
],
], 'workflow');
$this->setExpectedException(RequiredStateMissingException::class, "Required State Type Test' requires states with the ID 'fresh', 'rotten' in workflow 'test'");
$workflow->save();
......@@ -79,8 +77,6 @@ public function testChangeRequiredStateAPI() {
'id' => 'test',
'type' => 'workflow_type_required_state_test',
], 'workflow');
/** @var \Drupal\workflows\WorkflowInterface $workflow */
$workflow = $workflow->getTypePlugin()->initializeWorkflow($workflow);
$workflow->save();
// Ensure states added by default configuration can be changed.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment