public function TagFormView::buildForm in Extensible BBCode 8.3
Same name and namespace in other branches
- 4.0.x src/Form/TagFormView.php \Drupal\xbbcode\Form\TagFormView::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides EntityForm::buildForm
File
- src/
Form/ TagFormView.php, line 29
Class
- TagFormView
- A form for viewing a read-only BBCode tag.
Namespace
Drupal\xbbcode\FormCode
public function buildForm(array $form, FormStateInterface $form_state) : array {
$form = parent::buildForm($form, $form_state);
// Disable all form elements.
foreach (Element::children($form) as $key) {
$form[$key]['#required'] = FALSE;
// Actually disabling text fields makes their content non-selectable.
// Just make them look like it, and read-only.
$type = $form[$key]['#type'];
if ($type === 'textfield' || $type === 'textarea') {
$form[$key]['#attributes']['readonly'] = 'readonly';
$form[$key]['#wrapper_attributes']['class']['form-disabled'] = 'form-disabled';
}
else {
$form[$key]['#disabled'] = TRUE;
}
}
return $form;
}