Tabs.php in Entity Browser 8
File
src/Plugin/EntityBrowser/WidgetSelector/Tabs.php
View source
<?php
namespace Drupal\entity_browser\Plugin\EntityBrowser\WidgetSelector;
use Drupal\entity_browser\WidgetSelectorBase;
use Drupal\Core\Form\FormStateInterface;
class Tabs extends WidgetSelectorBase {
public function getForm(array &$form = [], FormStateInterface &$form_state = NULL) {
$element = [];
$browser = $form_state
->getFormObject()
->getEntityBrowser();
foreach ($this->widget_ids as $id => $label) {
$name = 'tab_selector_' . $id;
$element[$name] = [
'#type' => 'button',
'#attributes' => [
'class' => [
'tab',
],
],
'#value' => $label,
'#disabled' => $id == $this
->getDefaultWidget(),
'#executes_submit_callback' => TRUE,
'#limit_validation_errors' => [
[
$id,
],
],
'#submit' => [],
'#name' => $name,
'#widget_id' => $id,
'#access' => $browser
->getWidget($id)
->access(),
];
}
$element['#attached']['library'][] = 'entity_browser/tabs';
return $element;
}
public function submit(array &$form, FormStateInterface $form_state) {
if (($trigger = $form_state
->getTriggeringElement()) && strpos($trigger['#name'], 'tab_selector_') === 0) {
if (!empty($this->widget_ids[$trigger['#widget_id']])) {
return $trigger['#widget_id'];
}
}
}
}
Classes
Name |
Description |
Tabs |
Displays entity browser widgets as tabs. |