|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @file |
|
5
|
|
|
* Contains \Drupal\entity_browser\Form\GeneralInfoConfig. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Drupal\entity_browser\Form; |
|
9
|
|
|
|
|
10
|
|
|
use Drupal\Core\Form\FormBase; |
|
11
|
|
|
use Drupal\Core\Form\FormStateInterface; |
|
12
|
|
|
use Drupal\entity_browser\DisplayManager; |
|
13
|
|
|
use Drupal\entity_browser\SelectionDisplayManager; |
|
14
|
|
|
use Drupal\entity_browser\WidgetManager; |
|
15
|
|
|
use Drupal\entity_browser\WidgetSelectorManager; |
|
16
|
|
|
use Drupal\user\SharedTempStore; |
|
17
|
|
|
use Drupal\user\SharedTempStoreFactory; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
19
|
|
|
|
|
20
|
|
|
class GeneralInfoConfig extends FormBase { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Entity browser display plugin manager. |
|
24
|
|
|
* |
|
25
|
|
|
* @var \Drupal\entity_browser\DisplayManager |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $displayManager; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Entity browser widget selector plugin manager. |
|
31
|
|
|
* |
|
32
|
|
|
* @var \Drupal\entity_browser\WidgetSelectorManager |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $widgetSelectorManager; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Entity browser selection display plugin manager. |
|
38
|
|
|
* |
|
39
|
|
|
* @var \Drupal\entity_browser\SelectionDisplayManager |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $selectionDisplayManager; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Entity browser widget plugin manager. |
|
45
|
|
|
* |
|
46
|
|
|
* @var \Drupal\entity_browser\WidgetManager |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $widgetManager; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Tempstore Factory for keeping track of values in each step of the wizard. |
|
52
|
|
|
* |
|
53
|
|
|
* @var \Drupal\user\SharedTempStoreFactory |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $tempstore; |
|
56
|
|
|
|
|
57
|
|
|
protected $tempstoreId; |
|
58
|
|
|
protected $machineName; |
|
59
|
|
|
/** |
|
60
|
|
|
* Constructs GeneralInfoConfig form class. |
|
61
|
|
|
* |
|
62
|
|
|
* @param \Drupal\entity_browser\DisplayManager $display_manager |
|
63
|
|
|
* Entity browser display plugin manager. |
|
64
|
|
|
* @param \Drupal\entity_browser\WidgetSelectorManager $widget_selector |
|
|
|
|
|
|
65
|
|
|
* Entity browser widget selector plugin manager. |
|
66
|
|
|
* @param \Drupal\entity_browser\SelectionDisplayManager |
|
67
|
|
|
* Entity browser selection display plugin manager. |
|
68
|
|
|
*/ |
|
69
|
|
|
function __construct(DisplayManager $display_manager, WidgetSelectorManager $widget_selector_manager, SelectionDisplayManager $selection_display_manager, WidgetManager $widget_manager, SharedTempStoreFactory $temp_store, $tempstore_id = NULL, $machine_name = NULL) { |
|
|
|
|
|
|
70
|
|
|
$this->displayManager = $display_manager; |
|
71
|
|
|
$this->selectionDisplayManager = $selection_display_manager; |
|
72
|
|
|
$this->widgetSelectorManager = $widget_selector_manager; |
|
73
|
|
|
$this->widgetManager = $widget_manager; |
|
74
|
|
|
$this->tempStore = $temp_store; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* {@inheritdoc} |
|
79
|
|
|
*/ |
|
80
|
|
|
public static function create(ContainerInterface $container) { |
|
81
|
|
|
return new static( |
|
82
|
|
|
$container->get('plugin.manager.entity_browser.display'), |
|
83
|
|
|
$container->get('plugin.manager.entity_browser.widget_selector'), |
|
84
|
|
|
$container->get('plugin.manager.entity_browser.selection_display'), |
|
85
|
|
|
$container->get('plugin.manager.entity_browser.widget'), |
|
86
|
|
|
$container->get('user.shared_tempstore') |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritdoc} |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getFormId() { |
|
94
|
|
|
return 'entity_browser_general_info_config_form'; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* {@inheritdoc} |
|
99
|
|
|
*/ |
|
100
|
|
|
public function buildForm(array $form, FormStateInterface $form_state) { |
|
101
|
|
|
$cached_values = $form_state->getTemporaryValue('wizard'); |
|
102
|
|
|
/** @var \Drupal\entity_browser\EntityBrowserInterface $entity_browser */ |
|
103
|
|
|
$entity_browser = $cached_values['entity_browser']; |
|
104
|
|
|
|
|
105
|
|
|
$displays = []; |
|
106
|
|
|
foreach ($this->displayManager->getDefinitions() as $plugin_id => $plugin_definition) { |
|
107
|
|
|
$displays[$plugin_id] = $plugin_definition['label']; |
|
108
|
|
|
} |
|
109
|
|
|
$form['display'] = [ |
|
110
|
|
|
'#type' => 'select', |
|
111
|
|
|
'#title' => $this->t('Display plugin'), |
|
112
|
|
|
'#default_value' => $entity_browser->get('display') ? $entity_browser->getDisplay()->getPluginId() : NULL, |
|
113
|
|
|
'#options' => $displays, |
|
114
|
|
|
'#required' => TRUE, |
|
115
|
|
|
]; |
|
116
|
|
|
|
|
117
|
|
|
$widget_selectors = []; |
|
118
|
|
|
foreach ($this->widgetSelectorManager->getDefinitions() as $plugin_id => $plugin_definition) { |
|
119
|
|
|
$widget_selectors[$plugin_id] = $plugin_definition['label']; |
|
120
|
|
|
} |
|
121
|
|
|
$form['widget_selector'] = [ |
|
122
|
|
|
'#type' => 'select', |
|
123
|
|
|
'#title' => $this->t('Widget selector plugin'), |
|
124
|
|
|
'#default_value' => $entity_browser->get('widget_selector') ? $entity_browser->getWidgetSelector()->getPluginId() : NULL, |
|
125
|
|
|
'#options' => $widget_selectors, |
|
126
|
|
|
'#required' => TRUE, |
|
127
|
|
|
]; |
|
128
|
|
|
|
|
129
|
|
|
$selection_display = []; |
|
130
|
|
|
foreach ($this->selectionDisplayManager->getDefinitions() as $plugin_id => $plugin_definition) { |
|
131
|
|
|
$selection_display[$plugin_id] = $plugin_definition['label']; |
|
132
|
|
|
} |
|
133
|
|
|
$form['selection_display'] = [ |
|
134
|
|
|
'#type' => 'select', |
|
135
|
|
|
'#title' => $this->t('Selection display plugin'), |
|
136
|
|
|
'#default_value' => $entity_browser->get('selection_display') ? $entity_browser->getSelectionDisplay()->getPluginId() : NULL, |
|
137
|
|
|
'#options' => $selection_display, |
|
138
|
|
|
'#required' => TRUE, |
|
139
|
|
|
]; |
|
140
|
|
|
|
|
141
|
|
|
return $form; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* {@inheritdoc} |
|
146
|
|
|
*/ |
|
147
|
|
|
public function submitForm(array &$form, FormStateInterface $form_state) { |
|
148
|
|
|
/** @var \Drupal\entity_browser\EntityBrowserInterface $entity_browser */ |
|
149
|
|
|
$entity_browser = $form_state->getTemporaryValue('wizard')['entity_browser']; |
|
150
|
|
|
$entity_browser->setName($form_state->getValue('id')) |
|
151
|
|
|
->setLabel($form_state->getValue('label')) |
|
152
|
|
|
->setDisplay($form_state->getValue('display')) |
|
153
|
|
|
->setWidgetSelector($form_state->getValue('widget_selector')) |
|
154
|
|
|
->setSelectionDisplay($form_state->getValue('selection_display')); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
} |
|
158
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.