Issue #3421018 by mohit_aghera, smustgrave: Convert WorkflowType plugin discovery to attributes
(cherry picked from commit 60d9d6778e
)
merge-requests/6880/head
parent
41437f5b94
commit
e5e52023d6
|
@ -10,6 +10,8 @@ use Drupal\Core\Entity\EntityPublishedInterface;
|
||||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||||
use Drupal\content_moderation\ContentModerationState;
|
use Drupal\content_moderation\ContentModerationState;
|
||||||
|
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||||
|
use Drupal\workflows\Attribute\WorkflowType;
|
||||||
use Drupal\workflows\Plugin\WorkflowTypeBase;
|
use Drupal\workflows\Plugin\WorkflowTypeBase;
|
||||||
use Drupal\workflows\StateInterface;
|
use Drupal\workflows\StateInterface;
|
||||||
use Drupal\workflows\WorkflowInterface;
|
use Drupal\workflows\WorkflowInterface;
|
||||||
|
@ -17,20 +19,19 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attaches workflows to content entity types and their bundles.
|
* Attaches workflows to content entity types and their bundles.
|
||||||
*
|
|
||||||
* @WorkflowType(
|
|
||||||
* id = "content_moderation",
|
|
||||||
* label = @Translation("Content moderation"),
|
|
||||||
* required_states = {
|
|
||||||
* "draft",
|
|
||||||
* "published",
|
|
||||||
* },
|
|
||||||
* forms = {
|
|
||||||
* "configure" = "\Drupal\content_moderation\Form\ContentModerationConfigureForm",
|
|
||||||
* "state" = "\Drupal\content_moderation\Form\ContentModerationStateForm"
|
|
||||||
* },
|
|
||||||
* )
|
|
||||||
*/
|
*/
|
||||||
|
#[WorkflowType(
|
||||||
|
id: 'content_moderation',
|
||||||
|
label: new TranslatableMarkup('Content moderation'),
|
||||||
|
forms: [
|
||||||
|
'configure' => '\Drupal\content_moderation\Form\ContentModerationConfigureForm',
|
||||||
|
'state' => '\Drupal\content_moderation\Form\ContentModerationStateForm',
|
||||||
|
],
|
||||||
|
required_states: [
|
||||||
|
'draft',
|
||||||
|
'published',
|
||||||
|
]
|
||||||
|
)]
|
||||||
class ContentModeration extends WorkflowTypeBase implements ContentModerationInterface, ContainerFactoryPluginInterface {
|
class ContentModeration extends WorkflowTypeBase implements ContentModerationInterface, ContainerFactoryPluginInterface {
|
||||||
|
|
||||||
use StringTranslationTrait;
|
use StringTranslationTrait;
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\workflows\Attribute;
|
||||||
|
|
||||||
|
use Drupal\Component\Plugin\Attribute\Plugin;
|
||||||
|
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines a Workflow type attribute object.
|
||||||
|
*
|
||||||
|
* Plugin Namespace: Plugin\WorkflowType
|
||||||
|
*
|
||||||
|
* For a working example, see \Drupal\content_moderation\Plugin\Workflow\ContentModerate
|
||||||
|
*
|
||||||
|
* @see \Drupal\workflows\WorkflowTypeInterface
|
||||||
|
* @see \Drupal\workflows\WorkflowTypeManager
|
||||||
|
* @see workflow_type_info_alter()
|
||||||
|
* @see plugin_api
|
||||||
|
*/
|
||||||
|
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||||
|
class WorkflowType extends Plugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* States required to exist.
|
||||||
|
*
|
||||||
|
* Normally supplied by WorkflowType::defaultConfiguration().
|
||||||
|
*/
|
||||||
|
public array $required_states = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of optional form classes implementing PluginFormInterface.
|
||||||
|
*
|
||||||
|
* Forms which will be used for the workflow UI are:
|
||||||
|
* - 'configure' (\Drupal\workflows\WorkflowTypeInterface::PLUGIN_FORM_KEY)
|
||||||
|
* - 'state' (\Drupal\workflows\StateInterface::PLUGIN_FORM_KEY)
|
||||||
|
* - 'transition' (\Drupal\workflows\TransitionInterface::PLUGIN_FORM_KEY)
|
||||||
|
*
|
||||||
|
* @see \Drupal\Core\Plugin\PluginWithFormsInterface
|
||||||
|
* @see \Drupal\Core\Plugin\PluginFormInterface
|
||||||
|
* @see \Drupal\workflows\Plugin\WorkflowTypeConfigureFormBase
|
||||||
|
* @see \Drupal\workflows\Plugin\WorkflowTypeStateFormBase
|
||||||
|
* @see \Drupal\workflows\Plugin\WorkflowTypeTransitionFormBase
|
||||||
|
* @see \Drupal\workflows\WorkflowTypeInterface::PLUGIN_FORM_KEY
|
||||||
|
* @see \Drupal\workflows\StateInterface::PLUGIN_FORM_KEY
|
||||||
|
* @see \Drupal\workflows\TransitionInterface::PLUGIN_FORM_KEY
|
||||||
|
*/
|
||||||
|
public array $forms = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an Action attribute.
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
* The plugin ID.
|
||||||
|
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $label
|
||||||
|
* The label of the action.
|
||||||
|
* @param string[] $forms
|
||||||
|
* A list of optional form classes implementing PluginFormInterface.
|
||||||
|
* @param string[] $required_states
|
||||||
|
* States required to exist.
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public readonly string $id,
|
||||||
|
public readonly ?TranslatableMarkup $label = NULL,
|
||||||
|
array $forms = [],
|
||||||
|
array $required_states = [],
|
||||||
|
) {
|
||||||
|
$this->forms = $forms;
|
||||||
|
$this->required_states = $required_states;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ namespace Drupal\workflows;
|
||||||
use Drupal\Core\Cache\CacheBackendInterface;
|
use Drupal\Core\Cache\CacheBackendInterface;
|
||||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||||
use Drupal\workflows\Annotation\WorkflowType;
|
use Drupal\workflows\Attribute\WorkflowType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a Workflow type plugin manager.
|
* Provides a Workflow type plugin manager.
|
||||||
|
@ -28,7 +28,7 @@ class WorkflowTypeManager extends DefaultPluginManager {
|
||||||
* The module handler to invoke the alter hook with.
|
* The module handler to invoke the alter hook with.
|
||||||
*/
|
*/
|
||||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
|
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
|
||||||
parent::__construct('Plugin/WorkflowType', $namespaces, $module_handler, WorkflowTypeInterface::class, WorkflowType::class);
|
parent::__construct('Plugin/WorkflowType', $namespaces, $module_handler, WorkflowTypeInterface::class, WorkflowType::class, 'Drupal\workflows\Annotation\WorkflowType');
|
||||||
$this->alterInfo('workflow_type_info');
|
$this->alterInfo('workflow_type_info');
|
||||||
$this->setCacheBackend($cache_backend, 'workflow_type_info');
|
$this->setCacheBackend($cache_backend, 'workflow_type_info');
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,21 +3,22 @@
|
||||||
namespace Drupal\workflow_type_test\Plugin\WorkflowType;
|
namespace Drupal\workflow_type_test\Plugin\WorkflowType;
|
||||||
|
|
||||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||||
|
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||||
|
use Drupal\workflows\Attribute\WorkflowType;
|
||||||
use Drupal\workflows\Plugin\WorkflowTypeBase;
|
use Drupal\workflows\Plugin\WorkflowTypeBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test workflow type.
|
* Test workflow type.
|
||||||
*
|
|
||||||
* @WorkflowType(
|
|
||||||
* id = "workflow_type_complex_test",
|
|
||||||
* label = @Translation("Workflow Type Complex Test"),
|
|
||||||
* forms = {
|
|
||||||
* "configure" = "\Drupal\workflow_type_test\Form\ComplexTestTypeConfigureForm",
|
|
||||||
* "state" = "\Drupal\workflow_type_test\Form\ComplexTestTypeStateForm",
|
|
||||||
* "transition" = "\Drupal\workflow_type_test\Form\ComplexTestTypeTransitionForm",
|
|
||||||
* }
|
|
||||||
* )
|
|
||||||
*/
|
*/
|
||||||
|
#[WorkflowType(
|
||||||
|
id: 'workflow_type_complex_test',
|
||||||
|
label: new TranslatableMarkup('Workflow Type Complex Test'),
|
||||||
|
forms: [
|
||||||
|
'configure' => '\Drupal\workflow_type_test\Form\ComplexTestTypeConfigureForm',
|
||||||
|
'state' => '\Drupal\workflow_type_test\Form\ComplexTestTypeStateForm',
|
||||||
|
'transition' => '\Drupal\workflow_type_test\Form\ComplexTestTypeTransitionForm',
|
||||||
|
]
|
||||||
|
)]
|
||||||
class ComplexTestType extends WorkflowTypeBase {
|
class ComplexTestType extends WorkflowTypeBase {
|
||||||
|
|
||||||
use StringTranslationTrait;
|
use StringTranslationTrait;
|
||||||
|
|
|
@ -2,23 +2,24 @@
|
||||||
|
|
||||||
namespace Drupal\workflow_type_test\Plugin\WorkflowType;
|
namespace Drupal\workflow_type_test\Plugin\WorkflowType;
|
||||||
|
|
||||||
|
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||||
|
use Drupal\workflows\Attribute\WorkflowType;
|
||||||
use Drupal\workflows\Plugin\WorkflowTypeBase;
|
use Drupal\workflows\Plugin\WorkflowTypeBase;
|
||||||
use Drupal\workflows\State;
|
use Drupal\workflows\State;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test workflow type.
|
* Test workflow type.
|
||||||
*
|
|
||||||
* @WorkflowType(
|
|
||||||
* id = "predefined_states_workflow_test_type",
|
|
||||||
* label = @Translation("Predefined States Workflow Test Type"),
|
|
||||||
* required_states = {
|
|
||||||
* "pay_blinds",
|
|
||||||
* "bet",
|
|
||||||
* "raise",
|
|
||||||
* "fold",
|
|
||||||
* }
|
|
||||||
* )
|
|
||||||
*/
|
*/
|
||||||
|
#[WorkflowType(
|
||||||
|
id: 'predefined_states_workflow_test_type',
|
||||||
|
label: new TranslatableMarkup('Predefined States Workflow Test Type'),
|
||||||
|
required_states: [
|
||||||
|
'pay_blinds',
|
||||||
|
'bet',
|
||||||
|
'raise',
|
||||||
|
'fold',
|
||||||
|
]
|
||||||
|
)]
|
||||||
class PredefinedStatesWorkflowTestType extends WorkflowTypeBase {
|
class PredefinedStatesWorkflowTestType extends WorkflowTypeBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,20 +3,21 @@
|
||||||
namespace Drupal\workflow_type_test\Plugin\WorkflowType;
|
namespace Drupal\workflow_type_test\Plugin\WorkflowType;
|
||||||
|
|
||||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||||
|
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||||
|
use Drupal\workflows\Attribute\WorkflowType;
|
||||||
use Drupal\workflows\Plugin\WorkflowTypeBase;
|
use Drupal\workflows\Plugin\WorkflowTypeBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test workflow type.
|
* Test workflow type.
|
||||||
*
|
|
||||||
* @WorkflowType(
|
|
||||||
* id = "workflow_type_required_state_test",
|
|
||||||
* label = @Translation("Required State Type Test"),
|
|
||||||
* required_states = {
|
|
||||||
* "fresh",
|
|
||||||
* "rotten",
|
|
||||||
* }
|
|
||||||
* )
|
|
||||||
*/
|
*/
|
||||||
|
#[WorkflowType(
|
||||||
|
id: 'workflow_type_required_state_test',
|
||||||
|
label: new TranslatableMarkup('Required State Type Test'),
|
||||||
|
required_states: [
|
||||||
|
'fresh',
|
||||||
|
'rotten',
|
||||||
|
]
|
||||||
|
)]
|
||||||
class RequiredStateTestType extends WorkflowTypeBase {
|
class RequiredStateTestType extends WorkflowTypeBase {
|
||||||
|
|
||||||
use StringTranslationTrait;
|
use StringTranslationTrait;
|
||||||
|
|
|
@ -2,16 +2,17 @@
|
||||||
|
|
||||||
namespace Drupal\workflow_type_test\Plugin\WorkflowType;
|
namespace Drupal\workflow_type_test\Plugin\WorkflowType;
|
||||||
|
|
||||||
|
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||||
|
use Drupal\workflows\Attribute\WorkflowType;
|
||||||
use Drupal\workflows\Plugin\WorkflowTypeBase;
|
use Drupal\workflows\Plugin\WorkflowTypeBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test workflow type.
|
* Test workflow type.
|
||||||
*
|
|
||||||
* @WorkflowType(
|
|
||||||
* id = "workflow_type_test",
|
|
||||||
* label = @Translation("Workflow Type Test"),
|
|
||||||
* )
|
|
||||||
*/
|
*/
|
||||||
|
#[WorkflowType(
|
||||||
|
id: 'workflow_type_test',
|
||||||
|
label: new TranslatableMarkup('Workflow Type Test')
|
||||||
|
)]
|
||||||
class TestType extends WorkflowTypeBase {
|
class TestType extends WorkflowTypeBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,17 +4,18 @@ namespace Drupal\workflow_type_test\Plugin\WorkflowType;
|
||||||
|
|
||||||
use Drupal\Core\Access\AccessResult;
|
use Drupal\Core\Access\AccessResult;
|
||||||
use Drupal\Core\Session\AccountInterface;
|
use Drupal\Core\Session\AccountInterface;
|
||||||
|
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||||
|
use Drupal\workflows\Attribute\WorkflowType;
|
||||||
use Drupal\workflows\Plugin\WorkflowTypeBase;
|
use Drupal\workflows\Plugin\WorkflowTypeBase;
|
||||||
use Drupal\workflows\WorkflowInterface;
|
use Drupal\workflows\WorkflowInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A test workflow with custom state/transition access rules applied.
|
* A test workflow with custom state/transition access rules applied.
|
||||||
*
|
|
||||||
* @WorkflowType(
|
|
||||||
* id = "workflow_custom_access_type",
|
|
||||||
* label = @Translation("Workflow Custom Access Type Test"),
|
|
||||||
* )
|
|
||||||
*/
|
*/
|
||||||
|
#[WorkflowType(
|
||||||
|
id: 'workflow_custom_access_type',
|
||||||
|
label: new TranslatableMarkup('Workflow Custom Access Type Test')
|
||||||
|
)]
|
||||||
class WorkflowCustomAccessType extends WorkflowTypeBase {
|
class WorkflowCustomAccessType extends WorkflowTypeBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue