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 = array(), FormStateInterface &$form_state = NULL) {
24 foreach ($this->widget_ids as $id => $label) {
25 $name = 'tab_selector_' . $id;
26 $element[$name] = array(
28 '#attributes' => ['class' => ['tab']],
30 '#disabled' => $id == $this->getDefaultWidget(),
31 '#executes_submit_callback' => TRUE,
32 '#limit_validation_errors' => array(array($id)),
33 // #limit_validation_errors only takes effect if #submit is present.
40 $element['#attached']['library'][] = 'entity_browser/tabs';
48 public function submit(array &$form, FormStateInterface $form_state) {
49 if (($trigger = $form_state->getTriggeringElement()) && strpos($trigger['#name'], 'tab_selector_') === 0) {
50 if (!empty($this->widget_ids[$trigger['#widget_id']])) {
51 return $trigger['#widget_id'];