Loading core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php +14 −13 Original line number Diff line number Diff line Loading @@ -10,6 +10,8 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\content_moderation\ContentModerationState; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\workflows\Attribute\WorkflowType; use Drupal\workflows\Plugin\WorkflowTypeBase; use Drupal\workflows\StateInterface; use Drupal\workflows\WorkflowInterface; Loading @@ -17,20 +19,19 @@ /** * 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 { use StringTranslationTrait; Loading core/modules/workflows/src/Attribute/WorkflowType.php 0 → 100644 +71 −0 Original line number Diff line number Diff line <?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; } } core/modules/workflows/src/WorkflowTypeManager.php +2 −2 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\workflows\Annotation\WorkflowType; use Drupal\workflows\Attribute\WorkflowType; /** * Provides a Workflow type plugin manager. Loading @@ -28,7 +28,7 @@ class WorkflowTypeManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ 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->setCacheBackend($cache_backend, 'workflow_type_info'); } Loading core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/ComplexTestType.php +11 −10 Original line number Diff line number Diff line Loading @@ -3,21 +3,22 @@ namespace Drupal\workflow_type_test\Plugin\WorkflowType; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\workflows\Attribute\WorkflowType; use Drupal\workflows\Plugin\WorkflowTypeBase; /** * 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 { use StringTranslationTrait; Loading core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/PredefinedStatesWorkflowTestType.php +12 −11 Original line number Diff line number Diff line Loading @@ -2,23 +2,24 @@ 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\State; /** * 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 { /** Loading Loading
core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php +14 −13 Original line number Diff line number Diff line Loading @@ -10,6 +10,8 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\content_moderation\ContentModerationState; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\workflows\Attribute\WorkflowType; use Drupal\workflows\Plugin\WorkflowTypeBase; use Drupal\workflows\StateInterface; use Drupal\workflows\WorkflowInterface; Loading @@ -17,20 +19,19 @@ /** * 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 { use StringTranslationTrait; Loading
core/modules/workflows/src/Attribute/WorkflowType.php 0 → 100644 +71 −0 Original line number Diff line number Diff line <?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; } }
core/modules/workflows/src/WorkflowTypeManager.php +2 −2 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\workflows\Annotation\WorkflowType; use Drupal\workflows\Attribute\WorkflowType; /** * Provides a Workflow type plugin manager. Loading @@ -28,7 +28,7 @@ class WorkflowTypeManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ 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->setCacheBackend($cache_backend, 'workflow_type_info'); } Loading
core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/ComplexTestType.php +11 −10 Original line number Diff line number Diff line Loading @@ -3,21 +3,22 @@ namespace Drupal\workflow_type_test\Plugin\WorkflowType; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\workflows\Attribute\WorkflowType; use Drupal\workflows\Plugin\WorkflowTypeBase; /** * 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 { use StringTranslationTrait; Loading
core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/PredefinedStatesWorkflowTestType.php +12 −11 Original line number Diff line number Diff line Loading @@ -2,23 +2,24 @@ 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\State; /** * 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 { /** Loading