View source
<?php
namespace Drupal\webform\Plugin\WebformElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Element\WebformMessage as WebformMessageElement;
use Drupal\webform\Plugin\WebformElementBase;
use Drupal\webform\WebformSubmissionInterface;
class VerticalTabs extends WebformElementBase {
protected function defineDefaultProperties() {
return [
'title' => $this
->t('Vertical Tabs'),
'help' => '',
'help_title' => '',
'description' => '',
'more' => '',
'more_title' => '',
'title_display' => 'invisible',
'description_display' => '',
'help_display' => '',
'required' => FALSE,
'wrapper_attributes' => [],
'label_attributes' => [],
'default_tab' => '',
] + $this
->defineDefaultBaseProperties();
}
protected function defineDefaultBaseProperties() {
$properties = parent::defineDefaultBaseProperties();
unset($properties['prepopulate'], $properties['states_clear']);
return $properties;
}
public function isInput(array $element) {
return FALSE;
}
public function isContainer(array $element) {
return FALSE;
}
public function prepare(array &$element, WebformSubmissionInterface $webform_submission = NULL) {
parent::prepare($element, $webform_submission);
$element += [
'#title_display' => 'invisible',
];
return $element;
}
public function buildHtml(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
return [];
}
public function buildText(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
return [];
}
public function getRelatedTypes(array $element) {
return [];
}
public function getElementSelectorOptions(array $element) {
return [];
}
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
unset($form['element']['title']['#required']);
$form['vertical_tabs'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Vertical tabs settings'),
'#open' => TRUE,
];
$form['vertical_tabs']['vertical_tabs_message'] = [
'#type' => 'webform_message',
'#message_type' => 'info',
'#access' => TRUE,
'#message_message' => $this
->t("To add details and fieldsets this vertical tabs element, you must defined a custom <code>'#group': vertical_tab_key</code> property in the details or fieldset element with this vertical tabs' element key."),
'#message_close' => TRUE,
'#message_storage' => WebformMessageElement::STORAGE_SESSION,
];
$form['vertical_tabs']['default_tab'] = [
'#type' => 'textfield',
'#title' => $this
->t('Default tab'),
'#description' => $this
->t('The default tab must be the [id] attributes of the details or fieldset element.'),
];
return $form;
}
public function preview() {
return [];
}
}