FormTestDetailsForm.php in Drupal 8
File
core/modules/system/tests/modules/form_test/src/Form/FormTestDetailsForm.php
View source
<?php
namespace Drupal\form_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class FormTestDetailsForm extends FormBase {
public function getFormId() {
return 'form_test_details_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['meta'] = [
'#type' => 'details',
'#title' => 'Details element',
'#open' => TRUE,
];
$form['submit'] = [
'#type' => 'submit',
'#value' => 'Submit',
];
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
$form_state
->setErrorByName('meta', 'I am an error on the details element.');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
}
}