7
7
* Abstract class for PluginSettingsForm implementation.
8
8
*/
9
9
10
+ use Drupal \Component \Plugin \PluginManagerInterface ;
10
11
use Drupal \Core \Form \ConfigFormBase ;
11
12
use Drupal \Core \Form \FormStateInterface ;
12
13
@@ -20,36 +21,37 @@ abstract class PluginSettingsFormBase extends ConfigFormBase implements PluginSe
20
21
*
21
22
* @var \Drupal\Component\Plugin\PluginManagerInterface
22
23
*/
23
- protected $ manager ;
24
+ protected PluginManagerInterface $ manager ;
24
25
25
26
/**
26
27
* {@inheritdoc}
27
28
*/
28
- protected function getEditableConfigNames () {
29
+ protected function getEditableConfigNames (): array {
29
30
return [$ this ->getConfigId ()];
30
31
}
31
32
32
33
/**
33
34
* {@inheritdoc}
34
35
*/
35
- public function getFormId () {
36
+ public function getFormId (): string {
36
37
return $ this ->getConfigName () . '_settings_form_ ' . $ this ->getPluginIdFromRequest ();
37
38
}
38
39
39
40
/**
40
41
* {@inheritdoc}
41
42
*/
42
- public function buildForm (array $ form , FormStateInterface $ form_state ) {
43
+ public function buildForm (array $ form , FormStateInterface $ form_state ): array {
43
44
$ plugin_id = $ this ->getPluginIdFromRequest ();
44
45
$ instance = $ this ->getPluginInstance ($ plugin_id );
45
46
$ form = $ instance ->buildConfigurationForm ($ form , $ form_state );
47
+
46
48
return parent ::buildForm ($ form , $ form_state );
47
49
}
48
50
49
51
/**
50
52
* {@inheritdoc}
51
53
*/
52
- public function validateForm (array &$ form , FormStateInterface $ form_state ) {
54
+ public function validateForm (array &$ form , FormStateInterface $ form_state ): void {
53
55
$ plugin_id = $ this ->getPluginIdFromRequest ();
54
56
$ instance = $ this ->getPluginInstance ($ plugin_id );
55
57
$ instance ->validateConfigurationForm ($ form , $ form_state );
@@ -58,7 +60,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
58
60
/**
59
61
* {@inheritdoc}
60
62
*/
61
- public function submitForm (array &$ form , FormStateInterface $ form_state ) {
63
+ public function submitForm (array &$ form , FormStateInterface $ form_state ): void {
62
64
$ plugin_id = $ this ->getPluginIdFromRequest ();
63
65
$ instance = $ this ->getPluginInstance ($ plugin_id );
64
66
$ instance ->submitConfigurationForm ($ form , $ form_state );
@@ -77,6 +79,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
77
79
*/
78
80
protected function getPluginIdFromRequest () {
79
81
$ request = $ this ->getRequest ();
82
+
80
83
return $ request ->get ('_plugin_id ' );
81
84
}
82
85
@@ -89,11 +92,12 @@ protected function getPluginIdFromRequest() {
89
92
* @return object
90
93
* Plugin instance.
91
94
*
92
- * @throws PluginException
95
+ * @throws \Drupal\Component\Plugin\Exception\ PluginException
93
96
*/
94
- public function getPluginInstance ($ plugin_id ) {
97
+ public function getPluginInstance ($ plugin_id ): object {
95
98
$ configuration = $ this ->config ($ this ->getConfigId ())->get ();
96
99
$ instance = $ this ->manager ->createInstance ($ plugin_id , $ configuration );
100
+
97
101
return $ instance ;
98
102
}
99
103
@@ -103,7 +107,7 @@ public function getPluginInstance($plugin_id) {
103
107
* @return string
104
108
* Configuration object name.
105
109
*/
106
- protected function getConfigId () {
110
+ protected function getConfigId (): string {
107
111
return $ this ->getConfigName () . '. ' . $ this ->getPluginIdFromRequest ();
108
112
}
109
113
0 commit comments