QuickEditFieldForm::buildForm

public QuickEditFieldForm::buildForm(array $form, FormStateInterface $form_state, EntityInterface $entity = NULL, $field_name = NULL)

Builds a form for a single entity field.

Overrides FormInterface::buildForm

File

core/modules/quickedit/src/Form/QuickEditFieldForm.php, line 93

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;
}
doc_Drupal
2016-10-29 09:36:12
Comments
Leave a Comment

Please login to continue.