How to create a collapsible widget on Drupal 8

Drupal 8

There's a new render element type named details which is for creating a collapsible widget in Drupal 8. details is similar to the existing fieldset Form API element but details can be used even outside of forms.

The following render array $build builds a collapsible widget shown in the image below.

$build['author'] = [
  '#type' => 'details',
  '#title' => $this->t('Author'),

$build['author']['name'] = [
  '#type' => 'textfield',
  '#title' => $this->t('Name'),

a collapsible widget on Drupal 8

This sample is taken from the official d.o. page linked below.


後藤隼人 ( ごとうはやと )

Python や PHP を使ってソフトウェア開発やウェブ制作をしています。詳しくはこちら