public function AjaxToggleForm::buildForm in Toggle Editable fields 8
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 FormInterface::buildForm
File
- src/
Form/ AjaxToggleForm.php, line 104
Class
- AjaxToggleForm
- Build a form to switch state of targeted FieldItem.
Namespace
Drupal\toggle_editable_fields\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#tree'] = TRUE;
$form['checkbox'] = [
'#type' => 'checkbox',
'#default_value' => $this->defaultValue,
'#attributes' => [
'data-toggle' => 'toggle',
'class' => [
'checkbox-toggle',
],
],
'#ajax' => [
'callback' => [
$this,
'formListAjax',
],
'event' => 'change',
'progress' => [
'type' => 'none',
],
],
'#disabled' => !($this
->fieldIsEditable() || $this
->checkEditFieldAccess()),
];
// Add library.
$form['#attached']['library'][] = 'toggle_editable_fields/bootstrap.toogle';
$this
->setBooststrapDataAttributes($form['checkbox']);
return $form;
}