a254a4f31fe8776694ffd52b4bf07bd3db906782
[yaffs-website] / web / core / modules / workflows / tests / modules / workflow_type_test / src / Plugin / WorkflowType / ComplexTestType.php
1 <?php
2
3 namespace Drupal\workflow_type_test\Plugin\WorkflowType;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\Core\StringTranslation\StringTranslationTrait;
7 use Drupal\workflows\Plugin\WorkflowTypeBase;
8 use Drupal\workflows\StateInterface;
9 use Drupal\workflows\TransitionInterface;
10 use Drupal\workflows\WorkflowInterface;
11 use Drupal\workflow_type_test\DecoratedState;
12 use Drupal\workflow_type_test\DecoratedTransition;
13
14 /**
15  * Test workflow type.
16  *
17  * @WorkflowType(
18  *   id = "workflow_type_complex_test",
19  *   label = @Translation("Workflow Type Complex Test"),
20  * )
21  */
22 class ComplexTestType extends WorkflowTypeBase {
23
24   use StringTranslationTrait;
25
26   /**
27    * {@inheritDoc}
28    */
29   public function decorateState(StateInterface $state) {
30     if (isset($this->configuration['states'][$state->id()])) {
31       $state = new DecoratedState($state, $this->configuration['states'][$state->id()]['extra']);
32     }
33     else {
34       $state = new DecoratedState($state);
35     }
36     return $state;
37   }
38
39   /**
40    * {@inheritDoc}
41    */
42   public function decorateTransition(TransitionInterface $transition) {
43     if (isset($this->configuration['transitions'][$transition->id()])) {
44       $transition = new DecoratedTransition($transition, $this->configuration['transitions'][$transition->id()]['extra']);
45     }
46     else {
47       $transition = new DecoratedTransition($transition);
48     }
49     return $transition;
50   }
51
52   /**
53    * {@inheritdoc}
54    */
55   public function buildStateConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, StateInterface $state = NULL) {
56     /** @var \Drupal\workflow_type_test\DecoratedState $state */
57     $form = [];
58     $form['extra'] = [
59       '#type' => 'textfield',
60       '#title' => $this->t('Extra'),
61       '#description' => $this->t('Extra information added to state'),
62       '#default_value' => isset($state) ? $state->getExtra() : FALSE,
63     ];
64     return $form;
65   }
66
67   /**
68    * {@inheritdoc}
69    */
70   public function buildTransitionConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, TransitionInterface $transition = NULL) {
71     /** @var \Drupal\workflow_type_test\DecoratedTransition $transition */
72     $form = [];
73     $form['extra'] = [
74       '#type' => 'textfield',
75       '#title' => $this->t('Extra'),
76       '#description' => $this->t('Extra information added to transition'),
77       '#default_value' => isset($transition) ? $transition->getExtra() : FALSE,
78     ];
79     return $form;
80   }
81
82   /**
83    * {@inheritdoc}
84    */
85   public function onDependencyRemoval(array $dependencies) {
86     // Always return TRUE to allow the logic in
87     // \Drupal\workflows\Entity\Workflow::onDependencyRemoval() to be tested.
88     return TRUE;
89   }
90
91 }