gotohayato.com

太陽(ライトモード)

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.

参考

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

アバター
後藤隼人 ( ごとうはやと )GitHubPython

ウェブ制作・開発やマーケティング、プロジェクト支援などをしています。

© 2022 gotohayato.com
サイトについてタグアーカイブメッセージを送る