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\SharedTempStoreFactory; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* General information configuration step in entity browser form wizard. |
21
|
|
|
*/ |
22
|
|
|
class GeneralInfoConfig extends FormBase { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Entity browser display plugin manager. |
26
|
|
|
* |
27
|
|
|
* @var \Drupal\entity_browser\DisplayManager |
28
|
|
|
*/ |
29
|
|
|
protected $displayManager; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Entity browser widget selector plugin manager. |
33
|
|
|
* |
34
|
|
|
* @var \Drupal\entity_browser\WidgetSelectorManager |
35
|
|
|
*/ |
36
|
|
|
protected $widgetSelectorManager; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Entity browser selection display plugin manager. |
40
|
|
|
* |
41
|
|
|
* @var \Drupal\entity_browser\SelectionDisplayManager |
42
|
|
|
*/ |
43
|
|
|
protected $selectionDisplayManager; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Entity browser widget plugin manager. |
47
|
|
|
* |
48
|
|
|
* @var \Drupal\entity_browser\WidgetManager |
49
|
|
|
*/ |
50
|
|
|
protected $widgetManager; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Constructs GeneralInfoConfig form class. |
54
|
|
|
* |
55
|
|
|
* @param \Drupal\entity_browser\DisplayManager $display_manager |
56
|
|
|
* Entity browser display plugin manager. |
57
|
|
|
* @param \Drupal\entity_browser\WidgetSelectorManager $widget_selector_manager |
58
|
|
|
* Entity browser widget selector plugin manager. |
59
|
|
|
* @param \Drupal\entity_browser\SelectionDisplayManager $selection_display_manager |
60
|
|
|
* Entity browser selection display plugin manager. |
61
|
|
|
* @param \Drupal\entity_browser\WidgetManager $widget_manager |
62
|
|
|
* Entity browser widget plugin manager. |
63
|
|
|
*/ |
64
|
|
|
function __construct(DisplayManager $display_manager, WidgetSelectorManager $widget_selector_manager, SelectionDisplayManager $selection_display_manager, WidgetManager $widget_manager) { |
|
|
|
|
65
|
|
|
$this->displayManager = $display_manager; |
66
|
|
|
$this->selectionDisplayManager = $selection_display_manager; |
67
|
|
|
$this->widgetSelectorManager = $widget_selector_manager; |
68
|
|
|
$this->widgetManager = $widget_manager; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
public static function create(ContainerInterface $container) { |
75
|
|
|
return new static( |
76
|
|
|
$container->get('plugin.manager.entity_browser.display'), |
77
|
|
|
$container->get('plugin.manager.entity_browser.widget_selector'), |
78
|
|
|
$container->get('plugin.manager.entity_browser.selection_display'), |
79
|
|
|
$container->get('plugin.manager.entity_browser.widget') |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
|
|
public function getFormId() { |
87
|
|
|
return 'entity_browser_general_info_config_form'; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
|
|
public function buildForm(array $form, FormStateInterface $form_state) { |
94
|
|
|
$cached_values = $form_state->getTemporaryValue('wizard'); |
95
|
|
|
/** @var \Drupal\entity_browser\EntityBrowserInterface $entity_browser */ |
96
|
|
|
$entity_browser = $cached_values['entity_browser']; |
97
|
|
|
|
98
|
|
|
$displays = []; |
99
|
|
|
foreach ($this->displayManager->getDefinitions() as $plugin_id => $plugin_definition) { |
100
|
|
|
$displays[$plugin_id] = $plugin_definition['label']; |
101
|
|
|
} |
102
|
|
|
$form['display'] = [ |
103
|
|
|
'#type' => 'select', |
104
|
|
|
'#title' => $this->t('Display plugin'), |
105
|
|
|
'#default_value' => $entity_browser->get('display') ? $entity_browser->getDisplay()->getPluginId() : NULL, |
106
|
|
|
'#options' => $displays, |
107
|
|
|
'#required' => TRUE, |
108
|
|
|
]; |
109
|
|
|
|
110
|
|
|
$widget_selectors = []; |
111
|
|
|
foreach ($this->widgetSelectorManager->getDefinitions() as $plugin_id => $plugin_definition) { |
112
|
|
|
$widget_selectors[$plugin_id] = $plugin_definition['label']; |
113
|
|
|
} |
114
|
|
|
$form['widget_selector'] = [ |
115
|
|
|
'#type' => 'select', |
116
|
|
|
'#title' => $this->t('Widget selector plugin'), |
117
|
|
|
'#default_value' => $entity_browser->get('widget_selector') ? $entity_browser->getWidgetSelector()->getPluginId() : NULL, |
118
|
|
|
'#options' => $widget_selectors, |
119
|
|
|
'#required' => TRUE, |
120
|
|
|
]; |
121
|
|
|
|
122
|
|
|
$selection_display = []; |
123
|
|
|
foreach ($this->selectionDisplayManager->getDefinitions() as $plugin_id => $plugin_definition) { |
124
|
|
|
$selection_display[$plugin_id] = $plugin_definition['label']; |
125
|
|
|
} |
126
|
|
|
$form['selection_display'] = [ |
127
|
|
|
'#type' => 'select', |
128
|
|
|
'#title' => $this->t('Selection display plugin'), |
129
|
|
|
'#default_value' => $entity_browser->get('selection_display') ? $entity_browser->getSelectionDisplay()->getPluginId() : NULL, |
130
|
|
|
'#options' => $selection_display, |
131
|
|
|
'#required' => TRUE, |
132
|
|
|
]; |
133
|
|
|
|
134
|
|
|
return $form; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* {@inheritdoc} |
139
|
|
|
*/ |
140
|
|
|
public function submitForm(array &$form, FormStateInterface $form_state) { |
141
|
|
|
/** @var \Drupal\entity_browser\EntityBrowserInterface $entity_browser */ |
142
|
|
|
$entity_browser = $form_state->getTemporaryValue('wizard')['entity_browser']; |
143
|
|
|
$entity_browser->setName($form_state->getValue('id')) |
144
|
|
|
->setLabel($form_state->getValue('label')) |
145
|
|
|
->setDisplay($form_state->getValue('display')) |
146
|
|
|
->setWidgetSelector($form_state->getValue('widget_selector')) |
147
|
|
|
->setSelectionDisplay($form_state->getValue('selection_display')); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
} |
151
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.