Skip to content
Snippets Groups Projects
Commit db0b3588 authored by David Cameron's avatar David Cameron
Browse files

Issue #3478625 by dcam: Reduce form element reuse

parent 3683acc4
No related branches found
No related tags found
No related merge requests found
Pipeline #483456 passed
......@@ -190,41 +190,37 @@ class StyleguideForm extends FormBase {
'class' => ['button'],
],
];
$form['details-close'] = [
'#type' => 'details',
'#title' => $this->t('Details closed'),
'#open' => FALSE,
$form['fieldset'] = [
'#type' => 'fieldset',
'#title' => $this->t('Fieldset'),
'#description' => $this->generator->sentence(),
];
$form['details-open'] = [
'#type' => 'details',
'#title' => $this->t('Details open'),
'#open' => TRUE,
$form['fieldset']['child1'] = [
'#type' => 'textfield',
'#title' => $this->t('Fieldset Child 1'),
'#description' => $this->generator->sentence(),
];
$form['fieldset'] = [
'#type' => 'fieldset',
'#title' => $this->t('Fieldset'),
$form['fieldset']['child2'] = [
'#type' => 'textfield',
'#title' => $this->t('Fieldset Child 2'),
'#description' => $this->generator->sentence(),
];
$elements = ['fieldset', 'details-close', 'details-open'];
$count = 0;
foreach ($form as $key => $value) {
if ($value['#type'] != 'fieldset' && $value['#type'] != 'checkbox' && $count < 2) {
$count++;
foreach ($elements as $item) {
$form[$item][$key . '-' . $item] = $value;
}
}
}
$form['vertical_tabs']['elements'] = [
'#type' => 'vertical_tabs',
'#default_tab' => 'fieldset',
];
foreach ($elements as $element) {
$form['vertical_tabs'][$element] = $form[$element];
$form['vertical_tabs'][$element]['#type'] = 'details';
$form['vertical_tabs'][$element]['#group'] = 'elements';
'#default_tab' => 'tab1',
];
for ($count = 1; $count < 4; $count++) {
$form['vertical_tabs']['tab' . $count] = [
'#type' => 'details',
'#title' => $this->t('Tab @count', ['@count' => $count]),
'#description' => $this->generator->sentence(),
'#group' => 'elements',
];
$form['vertical_tabs']['tab' . $count]['content'] = [
'#type' => 'textfield',
'#title' => $this->t('Tab @count child', ['@count' => $count]),
'#description' => $this->generator->sentence(),
];
}
$form['markup'] = [
'#markup' => $this->t('<p><em>Markup</em>: Note that markup does not allow titles or descriptions. Use "item" for those options.</p>') . $this->generator->paragraphs(1, TRUE),
......
......@@ -116,6 +116,25 @@ class DefaultStyleguide extends StyleguidePluginBase {
],
],
];
$items['details'] = [
'title' => $this->t('Details'),
'content' => [
'details-close' => [
'#type' => 'details',
'#title' => $this->t('Details closed'),
'#open' => FALSE,
'#description' => $this->generator->sentence(),
'content' => $this->generator->paragraphs(1),
],
'details-open' => [
'#type' => 'details',
'#title' => $this->t('Details open'),
'#open' => TRUE,
'#description' => $this->generator->sentence(),
'content' => $this->generator->paragraphs(1),
],
],
];
$items['em'] = [
'title' => $this->t('Emphasis'),
'content' => [
......@@ -474,7 +493,6 @@ class DefaultStyleguide extends StyleguidePluginBase {
$form_state = new FormState();
$elements = $this->formBuilder->buildForm('Drupal\styleguide\Form\StyleguideForm', $form_state);
$basic = [];
$details = [];
$tabs = [];
$markup = [];
foreach (Element::children($elements) as $key) {
......@@ -484,9 +502,6 @@ class DefaultStyleguide extends StyleguidePluginBase {
elseif (!isset($elements[$key]['#type']) || $elements[$key]['#type'] === 'item') {
$markup[] = $key;
}
elseif ($elements[$key]['#type'] === 'details') {
$details[] = $key;
}
// We skip these since they are called out individually below.
elseif (!in_array($elements[$key]['#type'], [
'actions',
......@@ -515,11 +530,6 @@ class DefaultStyleguide extends StyleguidePluginBase {
'content' => $this->formBuilder->getForm('Drupal\styleguide\Form\StyleguideForm', $markup),
'group' => $this->t('Forms'),
];
$items['form-details'] = [
'title' => $this->t('Forms, details'),
'content' => $this->formBuilder->getForm('Drupal\styleguide\Form\StyleguideForm', $details),
'group' => $this->t('Forms'),
];
$items['form-fieldset'] = [
'title' => $this->t('Forms, fieldset'),
'content' => $this->formBuilder->getForm('Drupal\styleguide\Form\StyleguideForm', ['fieldset']),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment