public function EntityFormControllerNG::buildEntity

Overrides EntityFormController::buildEntity().

Overrides EntityFormController::buildEntity

1 call to EntityFormControllerNG::buildEntity()
EntityFormControllerNG::validate in drupal/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php
Overrides EntityFormController::validate().

File

drupal/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php, line 57
Definition of Drupal\Core\Entity\EntityFormControllerNG.

Class

EntityFormControllerNG
Entity form controller variant for entity types using the new property API.

Namespace

Drupal\Core\Entity

Code

public function buildEntity(array $form, array &$form_state) {
  $entity = clone $this
    ->getEntity($form_state);
  $entity_type = $entity
    ->entityType();
  $info = entity_get_info($entity_type);

  // @todo Exploit the Field API to process the submitted entity field.
  // Copy top-level form values that are not for fields to entity properties,
  // without changing existing entity properties that are not being edited by
  // this form. Copying field values must be done using field_attach_submit().
  $values_excluding_fields = $info['fieldable'] ? array_diff_key($form_state['values'], field_info_instances($entity_type, $entity
    ->bundle())) : $form_state['values'];
  $translation = $entity
    ->getTranslation($this
    ->getFormLangcode($form_state), FALSE);
  $definitions = $translation
    ->getPropertyDefinitions();
  foreach ($values_excluding_fields as $key => $value) {
    if (isset($definitions[$key])) {
      $translation->{$key} = $value;
    }
  }

  // Invoke all specified builders for copying form values to entity
  // properties.
  if (isset($form['#entity_builders'])) {
    foreach ($form['#entity_builders'] as $function) {
      call_user_func_array($function, array(
        $entity_type,
        $entity,
        &$form,
        &$form_state,
      ));
    }
  }

  // Copy field values to the entity.
  if ($info['fieldable']) {
    $entity
      ->setCompatibilityMode(TRUE);
    field_attach_submit($entity_type, $entity, $form, $form_state);
    $entity
      ->setCompatibilityMode(FALSE);
  }
  return $entity;
}