3 namespace Drupal\entity_browser\Plugin\EntityBrowser\WidgetSelector;
5 use Drupal\entity_browser\WidgetSelectorBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Displays entity browser widgets as tabs.
11 * @EntityBrowserWidgetSelector(
13 * label = @Translation("Tabs"),
14 * description = @Translation("Creates horizontal tabs on the top of the entity browser, each tab representing one available widget.")
17 class Tabs extends WidgetSelectorBase {
22 public function getForm(array &$form = [], FormStateInterface &$form_state = NULL) {
24 /** @var \Drupal\entity_browser\EntityBrowserInterface $browser */
25 $browser = $form_state->getFormObject()->getEntityBrowser();
26 foreach ($this->widget_ids as $id => $label) {
27 $name = 'tab_selector_' . $id;
30 '#attributes' => ['class' => ['tab']],
32 '#disabled' => $id == $this->getDefaultWidget(),
33 '#executes_submit_callback' => TRUE,
34 '#limit_validation_errors' => [[$id]],
35 // #limit_validation_errors only takes effect if #submit is present.
39 '#access' => $browser->getWidget($id)->access(),
43 $element['#attached']['library'][] = 'entity_browser/tabs';
51 public function submit(array &$form, FormStateInterface $form_state) {
52 if (($trigger = $form_state->getTriggeringElement()) && strpos($trigger['#name'], 'tab_selector_') === 0) {
53 if (!empty($this->widget_ids[$trigger['#widget_id']])) {
54 return $trigger['#widget_id'];