Fichier
-
src/Form/QuickTabsInstanceEditForm.php, line 78
Classe
- QuickTabsInstanceEditForm
- Class QuickTabsInstanceEditForm.
Namespace
Drupal\quicktabs\Form
Code
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['label'] = [
'#title' => $this->t('Name'),
'#description' => $this->t('This will appear as the block title.'),
'#type' => 'textfield',
'#default_value' => $this->entity
->label(),
'#weight' => -9,
'#required' => TRUE,
'#placeholder' => $this->t('Enter name'),
];
$form['id'] = [
'#type' => 'machine_name',
'#maxlength' => 32,
'#required' => TRUE,
'#default_value' => $this->entity
->id(),
'#machine_name' => [
'exists' => 'Drupal\\quicktabs\\Entity\\QuickTabsInstance::getQuickTabsInstance',
],
'#description' => $this->t('A unique machine-readable name for this QuickTabs instance. It must only contain lowercase letters, numbers, and underscores. The machine name will be used internally by QuickTabs and will be used in the CSS ID of your QuickTabs block.'),
'#weight' => -8,
];
$plugin_definitions = $this->tabRendererManager
->getDefinitions();
$renderers = [];
$renderer_form_options = [];
foreach ($plugin_definitions as $index => $def) {
$renderers[$index] = $def['name']->__toString();
$object = $this->tabRendererManager
->createInstance($index);
$renderer_form_options[$index] = $object->optionsForm($this->entity);
}
$form['renderer'] = [
'#type' => 'select',
'#title' => $this->t('Renderer'),
'#options' => $renderers,
'#default_value' => $this->entity
->getRenderer(),
'#description' => $this->t('Choose how to render the content.'),
'#weight' => -7,
];
$form['options'] = [
'#tree' => TRUE,
'#weight' => -6,
];
foreach ($renderer_form_options as $renderer => $options) {
foreach ($options as &$option) {
$option['#states'] = [
'visible' => [
':input[name="renderer"]' => [
'value' => $renderer,
],
],
];
}
$form['options'][$renderer] = $options;
}
$form['hide_empty_tabs'] = [
'#type' => 'checkbox',
'#title' => $this->t('Hide empty tabs'),
'#default_value' => $this->entity
->getHideEmptyTabs(),
'#description' => $this->t('Empty and restricted tabs will not be displayed. Could be useful when the tab content is not accessible.<br />This option does not work in ajax mode.'),
'#weight' => -3,
];
$tab_titles = [
QuickTabsInstance::QUICKTABS_DELTA_NONE => $this->t('- None -'),
];
$qt = new \stdClass();
if (!empty($form_state->getValue('configuration_data'))) {
$qt->tabs = $form_state->getValue('configuration_data');
}
else {
$qt->tabs = $this->entity
->getConfigurationData();
}
if (empty($qt->tabs)) {
$qt->tabs = [
0 => [],
1 => [],
];
}
else {
if (is_numeric($form_state->get('to_remove'))) {
unset($qt->tabs[$form_state->get('to_remove')]);
$form_state->set('num_tabs', $form_state->get('num_tabs') - 1);
}
if ($form_state->get('num_tabs') > count($qt->tabs)) {
$qt->tabs[] = [];
}
}
$delta = 0;
if (!empty($qt->tabs)) {
foreach ($qt->tabs as $tab) {
if (!empty($tab)) {
$tab_titles[$delta] = $tab['title'];
$delta++;
}
}
}
$form['default_tab'] = [
'#type' => 'select',
'#title' => $this->t('Default tab'),
'#options' => $tab_titles,
'#default_value' => $this->entity
->getDefaultTab(),
'#access' => !empty($tab_titles),
'#weight' => -4,
];
$form['configuration_data_wrapper'] = [
'#tree' => FALSE,
'#weight' => -3,
'#prefix' => '<div class="clear-block" id="configuration-data-wrapper">',
'#suffix' => '</div>',
];
$form['configuration_data_wrapper']['configuration_data'] = $this->getConfigurationDataForm($qt);
$form['tabs_more'] = [
'#name' => 'tabs_more',
'#type' => 'submit',
'#value' => $this->t('Add tab'),
'#attributes' => [
'class' => [
'add-tab',
],
'title' => $this->t('Click here to add more tabs.'),
],
'#weight' => 1,
'#submit' => [
[
$this,
'ajaxFormSubmit',
],
],
'#ajax' => [
'callback' => [
$this,
'ajaxFormCallback',
],
'progress' => [
'type' => 'throbber',
'message' => NULL,
],
'effect' => 'fade',
],
];
$form['#attached']['library'][] = 'quicktabs/quicktabs.form';
return $form;
}