You are here

public function QuickEditFieldForm::buildForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 98
Contains \Drupal\quickedit\Form\QuickEditFieldForm.

Class

QuickEditFieldForm
Builds and process a form for editing a single entity field.

Namespace

Drupal\quickedit\Form

Code

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'] = array(
      '#type' => 'hidden',
      '#value' => $entity
        ->getChangedTime(),
    );
  }

  // Add a submit button. Give it a class for easy JavaScript targeting.
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#attributes' => array(
      'class' => array(
        'quickedit-form-submit',
      ),
    ),
  );

  // Simplify it for optimal in-place use.
  $this
    ->simplify($form, $form_state);
  return $form;
}