function QuickEditFieldForm::buildEntity

Returns a cloned entity containing updated field values.

Calling code may then validate the returned entity, and if valid, transfer it back to the form state and save it.

2 calls to QuickEditFieldForm::buildEntity()
QuickEditFieldForm::submitForm in core/modules/quickedit/src/Form/QuickEditFieldForm.php
Saves the entity with updated values for the edited field.
QuickEditFieldForm::validateForm in core/modules/quickedit/src/Form/QuickEditFieldForm.php
Form validation handler.

File

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

Class

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

Namespace

Drupal\quickedit\Form

Code

protected function buildEntity(array $form, FormStateInterface $form_state) {
  /** @var \Drupal\Core\Entity\EntityInterface $entity */
  $entity = clone $form_state->get('entity');
  $field_name = $form_state->get('field_name');
  $form_state->get('form_display')
    ->extractFormValues($entity, $form, $form_state);
  // @todo Refine automated log messages and abstract them to all entity
  //   types: https://www.drupal.org/node/1678002.
  if ($entity->getEntityTypeId() == 'node' && $entity->isNewRevision() && $entity->revision_log
    ->isEmpty()) {
    $entity->revision_log = $this->t('Updated the %field-name field through in-place editing.', [
      '%field-name' => $entity->get($field_name)
        ->getFieldDefinition()
        ->getLabel(),
    ]);
  }
  return $entity;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.