"Drupal8表单构建元素(下拉列表)"
Published on Aug. 22, 2023, 12:06 p.m.
$form['example\_select'] = [
'#type' => 'select',
'#title' => $this->[t](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21StringTranslation%21StringTranslationTrait.php/function/StringTranslationTrait%3A%3At/8.2.x "Translates a string to the current language or to a given language.")('Select element'),
'#options' => [
'1' => $this->[t](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21StringTranslation%21StringTranslationTrait.php/function/StringTranslationTrait%3A%3At/8.2.x "Translates a string to the current language or to a given language.")('One'),
'2' => [
'2.1' => $this->[t](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21StringTranslation%21StringTranslationTrait.php/function/StringTranslationTrait%3A%3At/8.2.x "Translates a string to the current language or to a given language.")('Two point one'),
'2.2' => $this->[t](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21StringTranslation%21StringTranslationTrait.php/function/StringTranslationTrait%3A%3At/8.2.x "Translates a string to the current language or to a given language.")('Two point two'),
],
'3' => $this->[t](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21StringTranslation%21StringTranslationTrait.php/function/StringTranslationTrait%3A%3At/8.2.x "Translates a string to the current language or to a given language.")('Three'),
],
];