gotohayato.com

moon indicating dark mode
sun indicating light mode

How to create a collapsible widget on Drupal 8

2017/10/03Drupal 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.

<?php
$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.

参考

  • Details | Details.php | Drupal 8.4.x | Drupal API

関連記事


後藤隼人
個人事業でウェブ開発やマーケティングをしています。
GitHub