public function QuickEditFieldForm::buildForm in Drupal 8
Same name and namespace in other branches
- 9 core/modules/quickedit/src/Form/QuickEditFieldForm.php \Drupal\quickedit\Form\QuickEditFieldForm::buildForm()
Builds a form for a single entity field.
Overrides FormInterface::buildForm
File
- core/
modules/ quickedit/ src/ Form/ QuickEditFieldForm.php, line 83
Class
- QuickEditFieldForm
- Builds and process a form for editing a single entity field.
Namespace
Drupal\quickedit\FormCode
public function buildForm(array $form, FormStateInterface $form_state, EntityInterface $entity = NULL, $field_name = NULL) {
if (!$form_state
->has('entity')) {
$this
->init($form_state, $entity, $field_name);
}
// Add the field form.
$form_state
->get('form_display')
->buildForm($entity, $form, $form_state);
// Add a dummy changed timestamp field to attach form errors to.
if ($entity instanceof EntityChangedInterface) {
$form['changed_field'] = [
'#type' => 'hidden',
'#value' => $entity
->getChangedTime(),
];
}
// Add a submit button. Give it a class for easy JavaScript targeting.
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => t('Save'),
'#attributes' => [
'class' => [
'quickedit-form-submit',
],
],
];
// Use the non-inline form error display for Quick Edit forms, because in
// this case the errors are already near the form element.
$form['#disable_inline_form_errors'] = TRUE;
// Simplify it for optimal in-place use.
$this
->simplify($form, $form_state);
return $form;
}