DropDown.php in Entity Browser 8
File
src/Plugin/EntityBrowser/WidgetSelector/DropDown.php
View source
<?php
namespace Drupal\entity_browser\Plugin\EntityBrowser\WidgetSelector;
use Drupal\entity_browser\WidgetSelectorBase;
use Drupal\Core\Form\FormStateInterface;
class DropDown extends WidgetSelectorBase {
public function getForm(array &$form = [], FormStateInterface &$form_state = NULL) {
$form['#prefix'] = '<div id="entity-browser-form">';
$form['#suffix'] = '</div>';
$browser = $form_state
->getFormObject()
->getEntityBrowser();
$widget_ids = [];
foreach ($this->widget_ids as $widget_id => $widget_name) {
if ($browser
->getWidget($widget_id)
->access()
->isAllowed()) {
$widget_ids[$widget_id] = $widget_name;
}
}
$element['widget'] = [
'#type' => 'select',
'#options' => $widget_ids,
'#default_value' => $this
->getDefaultWidget(),
'#executes_submit_callback' => TRUE,
'#limit_validation_errors' => [
[
'widget',
],
],
'#submit' => [],
'#ajax' => [
'callback' => [
$this,
'changeWidgetCallback',
],
'wrapper' => 'entity-browser-form',
],
];
$element['change'] = [
'#type' => 'submit',
'#name' => 'change',
'#value' => $this
->t('Change'),
'#attributes' => [
'class' => [
'js-hide',
],
],
];
return $element;
}
public function submit(array &$form, FormStateInterface $form_state) {
return $form_state
->getValue('widget');
}
public function changeWidgetCallback(array &$form, FormStateInterface $form_state) {
return $form;
}
}
Classes
Name |
Description |
DropDown |
Displays widgets in a select list. |