3 namespace Drupal\entity_browser\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\entity_browser\DisplayManager;
8 use Drupal\entity_browser\SelectionDisplayManager;
9 use Drupal\entity_browser\WidgetManager;
10 use Drupal\entity_browser\WidgetSelectorManager;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
14 * General information configuration step in entity browser form wizard.
16 class GeneralInfoConfig extends FormBase {
19 * Entity browser display plugin manager.
21 * @var \Drupal\entity_browser\DisplayManager
23 protected $displayManager;
26 * Entity browser widget selector plugin manager.
28 * @var \Drupal\entity_browser\WidgetSelectorManager
30 protected $widgetSelectorManager;
33 * Entity browser selection display plugin manager.
35 * @var \Drupal\entity_browser\SelectionDisplayManager
37 protected $selectionDisplayManager;
40 * Entity browser widget plugin manager.
42 * @var \Drupal\entity_browser\WidgetManager
44 protected $widgetManager;
47 * Constructs GeneralInfoConfig form class.
49 * @param \Drupal\entity_browser\DisplayManager $display_manager
50 * Entity browser display plugin manager.
51 * @param \Drupal\entity_browser\WidgetSelectorManager $widget_selector_manager
52 * Entity browser widget selector plugin manager.
53 * @param \Drupal\entity_browser\SelectionDisplayManager $selection_display_manager
54 * Entity browser selection display plugin manager.
55 * @param \Drupal\entity_browser\WidgetManager $widget_manager
56 * Entity browser widget plugin manager.
58 function __construct(DisplayManager $display_manager, WidgetSelectorManager $widget_selector_manager, SelectionDisplayManager $selection_display_manager, WidgetManager $widget_manager) {
59 $this->displayManager = $display_manager;
60 $this->selectionDisplayManager = $selection_display_manager;
61 $this->widgetSelectorManager = $widget_selector_manager;
62 $this->widgetManager = $widget_manager;
68 public static function create(ContainerInterface $container) {
70 $container->get('plugin.manager.entity_browser.display'),
71 $container->get('plugin.manager.entity_browser.widget_selector'),
72 $container->get('plugin.manager.entity_browser.selection_display'),
73 $container->get('plugin.manager.entity_browser.widget')
80 public function getFormId() {
81 return 'entity_browser_general_info_config_form';
87 public function buildForm(array $form, FormStateInterface $form_state) {
88 $cached_values = $form_state->getTemporaryValue('wizard');
89 /** @var \Drupal\entity_browser\EntityBrowserInterface $entity_browser */
90 $entity_browser = $cached_values['entity_browser'];
92 if (empty($entity_browser->id())) {
93 $help_text = '<div class="clearfix eb-help-text"><h2>' . $this->t('Entity Browser creation instructions') . '</h2>';
94 $help_text .= '<p>' . $this->t('This is a multi-step form. In this first step you need to define the main characteristics of the Entity Browser (in other words, which plugins will be used for each functionality). In the following steps of this wizard, each individual plugin can be configured, when necessary.') . '</p>';
95 $help_text .= '<p>' . $this->t('You can find more detailed information about creating and configuring Entity Browsers at the <a href="@guide_href" target="_blank">official documentation</a>.', ['@guide_href' => 'https://drupal-media.gitbooks.io/drupal8-guide/content/modules/entity_browser/intro.html']) . '</p>';
96 $help_text .= '</div>';
97 $form['help_text'] = [
98 '#markup' => $help_text,
103 $display_description = $this->t('Choose here how the browser(s) should be presented to the end user. The available plugins are:') . '<ul>';
104 foreach ($this->displayManager->getDefinitions() as $plugin_id => $plugin_definition) {
105 $displays[$plugin_id] = $plugin_definition['label'];
106 $display_description .= '<li><b>' . $plugin_definition['label'] . ':</b> ' . $plugin_definition['description'] . '</li>';
108 $display_description .= '</ul>';
111 '#title' => $this->t('Display plugin'),
112 '#description' => $display_description,
113 '#default_value' => $entity_browser->get('display') ? $entity_browser->getDisplay()->getPluginId() : 'modal',
114 '#options' => $displays,
118 $widget_selectors = [];
119 $widget_description = $this->t('In the last step of the entity browser configuration you can decide how the widgets will be available to the editor. The available plugins are:') . '<ul>';
120 foreach ($this->widgetSelectorManager->getDefinitions() as $plugin_id => $plugin_definition) {
121 $widget_selectors[$plugin_id] = $plugin_definition['label'];
122 $widget_description .= '<li><b>' . $plugin_definition['label'] . ':</b> ' . $plugin_definition['description'] . '</li>';
124 $widget_description .= '</ul>';
125 $form['widget_selector'] = [
127 '#title' => $this->t('Widget selector plugin'),
128 '#description' => $widget_description,
129 '#default_value' => $entity_browser->get('widget_selector') ? $entity_browser->getWidgetSelector()->getPluginId() : 'tabs',
130 '#options' => $widget_selectors,
134 $selection_display = [];
135 $selection_description = $this->t('You can optionally allow a "work-in-progress selection zone" to be available to the editor, while still navigating, browsing and selecting the entities. The available plugins are:') . '<ul>';
136 foreach ($this->selectionDisplayManager->getDefinitions() as $plugin_id => $plugin_definition) {
137 $selection_display[$plugin_id] = $plugin_definition['label'];
138 $selection_description .= '<li><b>' . $plugin_definition['label'] . ':</b> ' . $plugin_definition['description'] . '</li>';
140 $selection_description .= '</ul>';
141 $form['selection_display'] = [
143 '#title' => $this->t('Selection display plugin'),
144 '#description' => $selection_description,
145 '#default_value' => $entity_browser->get('selection_display') ? $entity_browser->getSelectionDisplay()->getPluginId() : 'no_display',
146 '#options' => $selection_display,
156 public function submitForm(array &$form, FormStateInterface $form_state) {
157 /** @var \Drupal\entity_browser\EntityBrowserInterface $entity_browser */
158 $entity_browser = $form_state->getTemporaryValue('wizard')['entity_browser'];
159 $entity_browser->setName($form_state->getValue('id'))
160 ->setLabel($form_state->getValue('label'))
161 ->setDisplay($form_state->getValue('display'))
162 ->setWidgetSelector($form_state->getValue('widget_selector'))
163 ->setSelectionDisplay($form_state->getValue('selection_display'));