Commit 7dcd7031 authored by bojanz's avatar bojanz

Rename workflow guards to guards.

parent d2b98fb1
......@@ -50,12 +50,12 @@ default:
to: canceled
```
Transitions can be further restricted by [guards](https://github.com/bojanz/state_machine/blob/8.x-1.x/src/WorkflowGuard/WorkflowGuardInterface.php), which are implemented as tagged services:
Transitions can be further restricted by [guards](https://github.com/bojanz/state_machine/blob/8.x-1.x/src/Guard/GuardInterface.php), which are implemented as tagged services:
```yaml
mymodule.fulfillment_guard:
class: Drupal\mymodule\WorkflowGuard\FulfillmentGuard
class: Drupal\mymodule\Guard\FulfillmentGuard
tags:
- { name: state_machine.workflow_guard, group: order }
- { name: state_machine.guard, group: order }
```
The group argument allows the guard factory to only instantiate the guards relevant
to a specific workflow group.
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\state_machine\DependencyInjection\Compiler\WorkflowGuardsPass.
* Contains \Drupal\state_machine\DependencyInjection\Compiler\GuardsPass.
*/
namespace Drupal\state_machine\DependencyInjection\Compiler;
......@@ -13,16 +13,16 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
/**
* Adds the context provider service IDs to the context manager.
*/
class WorkflowGuardsPass implements CompilerPassInterface {
class GuardsPass implements CompilerPassInterface {
/**
* {@inheritdoc}
*
* Passes the grouped service IDs of workflow guards to the guard factory.
* Passes the grouped service IDs of guards to the guard factory.
*/
public function process(ContainerBuilder $container) {
$guards = [];
foreach ($container->findTaggedServiceIds('state_machine.workflow_guard') as $id => $attributes) {
foreach ($container->findTaggedServiceIds('state_machine.guard') as $id => $attributes) {
if (empty($attributes[0]['group'])) {
continue;
}
......@@ -30,7 +30,7 @@ class WorkflowGuardsPass implements CompilerPassInterface {
$guards[$attributes[0]['group']][] = $id;
}
$definition = $container->getDefinition('state_machine.workflow_guard_factory');
$definition = $container->getDefinition('state_machine.guard_factory');
$definition->addArgument($guards);
}
......
......@@ -2,14 +2,17 @@
/**
* @file
* Contains \Drupal\state_machine\WorkflowGuard\WorkflowGuardFactory.
* Contains \Drupal\state_machine\Guard\GuardFactory.
*/
namespace Drupal\state_machine\WorkflowGuard;
namespace Drupal\state_machine\Guard;
use Symfony\Component\DependencyInjection\ContainerInterface;
class WorkflowGuardFactory {
/**
* Default implementation of the guard factory.
*/
class GuardFactory {
/**
* The service container.
......@@ -26,7 +29,7 @@ class WorkflowGuardFactory {
protected $guardServiceIds;
/**
* Constructs a new WorkflowGuardFactory object.
* Constructs a new GuardFactory object.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The service container.
......
<?php
/**
* @file
* Contains \Drupal\state_machine\Guard\GuardFactoryInterface.
*/
namespace Drupal\state_machine\Guard;
/**
* Defines the interface for guard factories.
*/
interface GuardFactoryInterface {
/**
* Gets the instantiated guards for the given group id.
*
* @param string $group_id
* The group id.
*
* @return \Drupal\state_machine\Guard\GuardInterface[]
*/
public function get($group_id);
}
......@@ -2,17 +2,17 @@
/**
* @file
* Contains \Drupal\state_machine\WorkflowGuard\WorkflowGuardInterface.
* Contains \Drupal\state_machine\Guard\GuardInterface.
*/
namespace Drupal\state_machine\WorkflowGuard;
namespace Drupal\state_machine\Guard;
use Drupal\state_machine\Plugin\Workflow\WorkflowInterface;
use Drupal\state_machine\Plugin\Workflow\WorkflowTransition;
use Drupal\Core\Entity\EntityInterface;
/**
* Defines the interface for workflow guards.
* Defines the interface for guards.
*
* Allows for custom logic controling the availability of specific transitions.
* Transitions could be restricted based on the current user's permissions, a
......@@ -20,7 +20,7 @@ use Drupal\Core\Entity\EntityInterface;
*
* By default, a transition is allowed unless at least one guard returns FALSE.
*/
interface WorkflowGuardInterface {
interface GuardInterface {
/**
* Checks whether the given transition is allowed.
......
......@@ -7,7 +7,7 @@
namespace Drupal\state_machine\Plugin\Workflow;
use Drupal\state_machine\WorkflowGuard\WorkflowGuardFactoryInterface;
use Drupal\state_machine\Guard\GuardFactoryInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
......@@ -19,9 +19,9 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class Workflow extends PluginBase implements WorkflowInterface, ContainerFactoryPluginInterface {
/**
* The workflow guard factory.
* The guard factory.
*
* @var \Drupal\state_machine\WorkflowGuard\WorkflowGuardFactoryInterface
* @var \Drupal\state_machine\Guard\GuardFactoryInterface
*/
protected $guardFactory;
......@@ -48,10 +48,10 @@ class Workflow extends PluginBase implements WorkflowInterface, ContainerFactory
* The workflow plugin_id.
* @param mixed $plugin_definition
* The workflow plugin implementation definition.
* @param \Drupal\state_machine\WorkflowGuard\WorkflowGuardFactoryInterface $guard_factory
* The workflow guard factory.
* @param \Drupal\state_machine\Guard\GuardFactoryInterface $guard_factory
* The guard factory.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, WorkflowGuardFactoryInterface $guard_factory) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, GuardFactoryInterface $guard_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->guardFactory = $guard_factory;
......@@ -78,7 +78,7 @@ class Workflow extends PluginBase implements WorkflowInterface, ContainerFactory
$configuration,
$plugin_id,
$plugin_definition,
$container->get('state_machine.workflow_guard_factory')
$container->get('state_machine.guard_factory')
);
}
......
......@@ -9,10 +9,10 @@ namespace Drupal\state_machine;
use Drupal\Core\DependencyInjection\ServiceProviderInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\state_machine\DependencyInjection\Compiler\WorkflowGuardsPass;
use Drupal\state_machine\DependencyInjection\Compiler\GuardsPass;
/**
* Registers the workflow guard compiler pass.
* Registers the guard compiler pass.
*/
class StateMachineServiceProvider implements ServiceProviderInterface {
......@@ -20,7 +20,7 @@ class StateMachineServiceProvider implements ServiceProviderInterface {
* {@inheritdoc}
*/
public function register(ContainerBuilder $container) {
$container->addCompilerPass(new WorkflowGuardsPass());
$container->addCompilerPass(new GuardsPass());
}
}
<?php
/**
* @file
* Contains \Drupal\state_machine\WorkflowGuard\WorkflowGuardFactoryInterface.
*/
namespace Drupal\state_machine\WorkflowGuard;
/**
* Defines the interface for workflow guard factories.
*/
interface WorkflowGuardFactoryInterface {
/**
* Gets the instantiated workflow guards for the given group id.
*
* @param string $group_id
* The group id.
*
* @return \Drupal\state_machine\WorkflowGuard\WorkflowGuardInterface[]
*/
public function get($group_id);
}
services:
state_machine.workflow_guard_factory:
class: Drupal\state_machine\WorkflowGuard\WorkflowGuardFactory
state_machine.guard_factory:
class: Drupal\state_machine\Guard\GuardFactory
arguments: ['@service_container']
plugin.manager.workflow:
......
......@@ -2,17 +2,17 @@
/**
* @file
* Contains \Drupal\state_machine_test\WorkflowGuard\FulfillmentGuard.
* Contains \Drupal\state_machine_test\Guard\FulfillmentGuard.
*/
namespace Drupal\state_machine_test\WorkflowGuard;
namespace Drupal\state_machine_test\Guard;
use Drupal\state_machine\WorkflowGuard\WorkflowGuardInterface;
use Drupal\state_machine\Guard\GuardInterface;
use Drupal\state_machine\Plugin\Workflow\WorkflowInterface;
use Drupal\state_machine\Plugin\Workflow\WorkflowTransition;
use Drupal\Core\Entity\EntityInterface;
class FulfillmentGuard implements WorkflowGuardInterface {
class FulfillmentGuard implements GuardInterface {
/**
* {@inheritdoc}
......
state_machine_test.fulfillment_guard:
class: Drupal\state_machine_test\WorkflowGuard\FulfillmentGuard
class: Drupal\state_machine_test\Guard\FulfillmentGuard
tags:
- { name: state_machine.workflow_guard, group: order }
- { name: state_machine.guard, group: order }
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