Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
82.14% |
23 / 28 |
|
76.47% |
13 / 17 |
CRAP | |
0.00% |
0 / 1 |
ConfigurableAuthorizationPluginBase | |
82.14% |
23 / 28 |
|
76.47% |
13 / 17 |
18.65 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
create | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
label | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getDescription | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTokens | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
defaultConfiguration | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getConfiguration | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setConfiguration | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
buildConfigurationForm | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
validateConfigurationForm | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
submitConfigurationForm | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
buildRowForm | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
validateRowForm | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
buildRowDescription | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
submitRowForm | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
calculateDependencies | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Drupal\authorization\Plugin; |
6 | |
7 | use Drupal\Core\Entity\DependencyTrait; |
8 | use Drupal\Core\Form\FormStateInterface; |
9 | use Drupal\Core\Plugin\PluginBase; |
10 | use Drupal\Core\StringTranslation\TranslatableMarkup; |
11 | use Symfony\Component\DependencyInjection\ContainerInterface; |
12 | |
13 | /** |
14 | * Provides a base class for all configurable Authorization plugins. |
15 | */ |
16 | abstract class ConfigurableAuthorizationPluginBase extends PluginBase implements ConfigurableAuthorizationPluginInterface { |
17 | |
18 | use DependencyTrait; |
19 | |
20 | /** |
21 | * Type. |
22 | * |
23 | * @var string |
24 | */ |
25 | protected $type; |
26 | |
27 | /** |
28 | * {@inheritdoc} |
29 | */ |
30 | public function __construct( |
31 | array $configuration, |
32 | string $plugin_id, |
33 | array $plugin_definition, |
34 | ) { |
35 | $configuration += $this->defaultConfiguration(); |
36 | parent::__construct($configuration, $plugin_id, $plugin_definition); |
37 | } |
38 | |
39 | /** |
40 | * {@inheritdoc} |
41 | */ |
42 | public static function create( |
43 | ContainerInterface $container, |
44 | array $configuration, |
45 | $plugin_id, |
46 | $plugin_definition, |
47 | ) { |
48 | $plugin = new static($configuration, $plugin_id, $plugin_definition); |
49 | |
50 | /** @var \Drupal\Core\StringTranslation\TranslationInterface $translation */ |
51 | $translation = $container->get('string_translation'); |
52 | $plugin->setStringTranslation($translation); |
53 | |
54 | return $plugin; |
55 | } |
56 | |
57 | /** |
58 | * {@inheritdoc} |
59 | */ |
60 | public function label(): TranslatableMarkup { |
61 | $plugin_definition = $this->getPluginDefinition(); |
62 | return $plugin_definition['label']; |
63 | } |
64 | |
65 | /** |
66 | * {@inheritdoc} |
67 | */ |
68 | public function getDescription() { |
69 | $plugin_definition = $this->getPluginDefinition(); |
70 | return $plugin_definition['description'] ?? ''; |
71 | } |
72 | |
73 | /** |
74 | * {@inheritdoc} |
75 | */ |
76 | public function getType(): string { |
77 | return $this->type; |
78 | } |
79 | |
80 | /** |
81 | * {@inheritdoc} |
82 | */ |
83 | public function getTokens(): array { |
84 | $tokens = []; |
85 | $tokens['@' . $this->getType() . '_name'] = $this->label(); |
86 | $tokens['@' . $this->getType() . '_mappingDirections'] = ''; |
87 | $tokens['@examples'] = ''; |
88 | return $tokens; |
89 | } |
90 | |
91 | /** |
92 | * {@inheritdoc} |
93 | */ |
94 | public function defaultConfiguration(): array { |
95 | return []; |
96 | } |
97 | |
98 | /** |
99 | * Unused, configuration is saved in the profile, required by base class. |
100 | */ |
101 | public function getConfiguration() { |
102 | return []; |
103 | } |
104 | |
105 | /** |
106 | * Unused, configuration is saved in the profile, required by base class. |
107 | * |
108 | * @param array $configuration |
109 | * Configuration. |
110 | */ |
111 | public function setConfiguration(array $configuration) {} |
112 | |
113 | /** |
114 | * {@inheritdoc} |
115 | */ |
116 | public function buildConfigurationForm(array $form, FormStateInterface $form_state): array { |
117 | return []; |
118 | } |
119 | |
120 | /** |
121 | * {@inheritdoc} |
122 | */ |
123 | public function validateConfigurationForm(array &$form, FormStateInterface $form_state): void {} |
124 | |
125 | /** |
126 | * {@inheritdoc} |
127 | */ |
128 | public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {} |
129 | |
130 | /** |
131 | * {@inheritdoc} |
132 | */ |
133 | public function buildRowForm(array $form, FormStateInterface $form_state, $index): array { |
134 | // Should be removed. |
135 | return []; |
136 | } |
137 | |
138 | /** |
139 | * {@inheritdoc} |
140 | */ |
141 | public function validateRowForm(array &$form, FormStateInterface $form_state): void {} |
142 | |
143 | /** |
144 | * {@inheritdoc} |
145 | */ |
146 | public function buildRowDescription(array $form, FormStateInterface $form_state): string { |
147 | // Should be removed. |
148 | return ""; |
149 | } |
150 | |
151 | /** |
152 | * {@inheritdoc} |
153 | */ |
154 | public function submitRowForm(array &$form, FormStateInterface $form_state): void {} |
155 | |
156 | /** |
157 | * {@inheritdoc} |
158 | */ |
159 | public function calculateDependencies(): array { |
160 | $this->addDependency('module', $this->getPluginDefinition()['provider']); |
161 | return $this->dependencies; |
162 | } |
163 | |
164 | } |