3 namespace Drupal\workflows\Plugin;
5 use Drupal\Component\Plugin\PluginBase;
6 use Drupal\Component\Utility\NestedArray;
7 use Drupal\Core\Access\AccessResult;
8 use Drupal\Core\Form\FormStateInterface;
9 use Drupal\Core\Session\AccountInterface;
10 use Drupal\workflows\StateInterface;
11 use Drupal\workflows\TransitionInterface;
12 use Drupal\workflows\WorkflowInterface;
13 use Drupal\workflows\WorkflowTypeInterface;
16 * A base class for Workflow type plugins.
18 * @see \Drupal\workflows\Annotation\WorkflowType
21 * The workflow system is currently experimental and should only be leveraged
22 * by experimental modules and development releases of contributed modules.
24 abstract class WorkflowTypeBase extends PluginBase implements WorkflowTypeInterface {
29 public function __construct(array $configuration, $plugin_id, $plugin_definition) {
30 parent::__construct($configuration, $plugin_id, $plugin_definition);
31 $this->setConfiguration($configuration);
37 public function initializeWorkflow(WorkflowInterface $workflow) {
44 public function label() {
45 $definition = $this->getPluginDefinition();
46 // The label can be an object.
47 // @see \Drupal\Core\StringTranslation\TranslatableMarkup
48 return $definition['label'];
54 public function checkWorkflowAccess(WorkflowInterface $entity, $operation, AccountInterface $account) {
55 return AccessResult::neutral();
61 public function decorateState(StateInterface $state) {
68 public function deleteState($state_id) {
69 unset($this->configuration['states'][$state_id]);
75 public function decorateTransition(TransitionInterface $transition) {
82 public function deleteTransition($transition_id) {
83 unset($this->configuration['transitions'][$transition_id]);
89 public function buildStateConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, StateInterface $state = NULL) {
96 public function buildTransitionConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, TransitionInterface $transition = NULL) {
103 public function getConfiguration() {
104 return $this->configuration;
110 public function setConfiguration(array $configuration) {
111 $this->configuration = NestedArray::mergeDeep(
112 $this->defaultConfiguration(),
120 public function getRequiredStates() {
121 return $this->getPluginDefinition()['required_states'];
127 public function defaultConfiguration() {
137 public function calculateDependencies() {
144 public function onDependencyRemoval(array $dependencies) {
151 public function getInitialState(WorkflowInterface $workflow) {
152 $ordered_states = $workflow->getStates();
153 return reset($ordered_states);