public function MultiStepDisplay::buildConfigurationForm in Entity Browser 8
Same name and namespace in other branches
- 8.2 src/Plugin/EntityBrowser/SelectionDisplay/MultiStepDisplay.php \Drupal\entity_browser\Plugin\EntityBrowser\SelectionDisplay\MultiStepDisplay::buildConfigurationForm()
Implements PluginFormInterface::buildConfigurationForm().
Overrides PluginConfigurationFormTrait::buildConfigurationForm
File
- src/
Plugin/ EntityBrowser/ SelectionDisplay/ MultiStepDisplay.php, line 422
Class
- MultiStepDisplay
- Show current selection and delivers selected entities.
Namespace
Drupal\entity_browser\Plugin\EntityBrowser\SelectionDisplayCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$entity_browser = $form_state
->getFormObject()
->getEntity();
$defaults = $entity_browser
->getSelectionDisplay()
->getConfiguration();
$default_entity_type = $defaults['entity_type'];
$default_display = $defaults['display'];
$default_display_settings = $defaults['display_settings'];
$default_display_settings += [
'entity_type' => $default_entity_type,
];
$entity_types = [];
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
/** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
$entity_types[$entity_type_id] = $entity_type
->getLabel();
}
$form['multi_step_form_wrapper'] = [
'#type' => 'container',
];
$form['entity_type'] = [
'#type' => 'select',
'#title' => $this
->t('Entity type'),
'#description' => $this
->t("Entity browser itself does not need information about entity type being selected. It can actually select entities of different type. However, some of the display plugins need to know which entity type they are operating with. Display plugins that do not need this info will ignore this configuration value."),
'#default_value' => $default_entity_type,
'#options' => $entity_types,
'#ajax' => [
'callback' => [
$this,
'updateSettingsAjax',
],
'wrapper' => 'selection-display-config-ajax-wrapper',
],
];
$displays = [];
foreach ($this->fieldDisplayManager
->getDefinitions() as $display_plugin_id => $definition) {
$entity_type = $this->entityTypeManager
->getDefinition($default_entity_type);
if ($this->fieldDisplayManager
->createInstance($display_plugin_id)
->isApplicable($entity_type)) {
$displays[$display_plugin_id] = $definition['label'];
}
}
$form['display'] = [
'#title' => $this
->t('Entity display plugin'),
'#type' => 'select',
'#default_value' => $default_display,
'#options' => $displays,
'#ajax' => [
'callback' => [
$this,
'updateSettingsAjax',
],
'wrapper' => 'selection-display-config-ajax-wrapper',
],
];
$form['display_settings'] = [
'#type' => 'container',
'#title' => $this
->t('Entity display plugin configuration'),
'#tree' => TRUE,
];
if ($default_display_settings) {
$display_plugin = $this->fieldDisplayManager
->createInstance($default_display, $default_display_settings);
$form['display_settings'] += $display_plugin
->settingsForm($form, $form_state);
}
$form['select_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('Select button text'),
'#default_value' => $defaults['select_text'],
'#description' => $this
->t('Text to display on the entity browser select button.'),
];
$form['selection_hidden'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Selection hidden by default'),
'#default_value' => $defaults['selection_hidden'],
'#description' => $this
->t('Whether or not the selection should be hidden by default.'),
];
return $form;
}