13

In Drupal 7 there was option to have fieldset collapsible or not, and to restrict default state of this form element (collapsed, or uncollapsed). Example:

$form['contact_data'] = array(
        '#title' => t("Contact data"),
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
);

Now, in Drupal 8 I cannot find attributtes #collapsible and #collapsed in Drupal\Core\Render\Element\Fieldset. In official documentation of Fieldset element is not mentioned any new element, which should substitute the Fieldset element.

Also there is not Form API elements overview for Drupal 8, such as for Drupal 7. You have to manually search for all Render Elements definition in code, which is more time consuming (especially when you would like to see elements overview and compare them).

26

All collapsible fieldsets have been replaced with HTML5 details elements.

Fieldset and legand are very hard to style and its not recommended to use with Drupal 8 any more. Instead its replaced with more cross browser way, which is the HTML5 Details & Summary tags.

'#type' => 'details'

https://www.drupal.org/node/1852020

Drupal 7

$form['advanced'] = array(
  '#type' => 'fieldset',
  '#title' => t('Advanced settings'),
  '#collapsible' => TRUE,
  '#collapsed' => FALSE,
  '#description' => t('Lorem ipsum.'),
);

Drupal 8

$form['advanced'] = array(
  '#type' => 'details',
  '#title' => t('Advanced settings'),
  '#description' => t('Lorem ipsum.'),
  '#open' => TRUE, // Controls the HTML5 'open' attribute. Defaults to FALSE.
);
| improve this answer | |
  • 2
    Thanks you for answer. But again, I am very frustrated from the fact, that this (not small) change is only described on some "change record" page and is not updated to official documentation pages... See: Online documentation: Not done... – Juraj Nemec Nov 15 '16 at 10:03
  • 1
    Change records are the perfect place to look for how thing X changed in Druapl 8. They're easily searchable and always contain before/after examples. Both code and documentation is mostly written in people's free time. Don't complain, help improve it. – Berdir Nov 15 '16 at 20:56
  • @Berdir Yes, I know that documentation in written in free time and I appreciate that :) But personally I don't think, that change records are easily searchable (except from google). Primary, as developer, you search in documentation (or API documentation), so just simple link reference to specific change record would be sufficient (and it is not as time consuming as writing those examples in change records). Apart from that, I must admit, that the code examples in change records are very good. – Juraj Nemec Nov 16 '16 at 8:46
  • Where do you ad this code in drupal 8 files? – DavSev Oct 9 '18 at 10:47
0

Example using HereDoc notation to store the HTML Description:

$desc_html = <<<HTML
<p>
  <strong>Put the HTML to be displayed when open in here.</strong>
<p>
HTML;

$form['advanced'] = array(
  '#type' => 'details',
  '#title' => t('Advanced settings'),
  '#description' => t($desc_html),
  '#open' => TRUE, // Controls the HTML5 'open' attribute. Defaults to FALSE.
);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.