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