public function EntityFormControllerNG::buildEntity

Overrides EntityFormController::buildEntity().

Overrides EntityFormController::buildEntity

5 calls to EntityFormControllerNG::buildEntity()
CommentFormController::buildEntity in drupal/core/modules/comment/lib/Drupal/comment/CommentFormController.php
Overrides EntityFormController::buildEntity().
CustomBlockFormController::delete in drupal/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php
Overrides \Drupal\Core\Entity\EntityFormController::delete().
EntityFormControllerNG::validate in drupal/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php
Overrides EntityFormController::validate().
FeedFormController::validate in drupal/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php
Overrides Drupal\Core\Entity\EntityFormController::validate().
TermFormController::buildEntity in drupal/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php
Overrides Drupal\Core\Entity\EntityFormController::buildEntity().
2 methods override EntityFormControllerNG::buildEntity()
CommentFormController::buildEntity in drupal/core/modules/comment/lib/Drupal/comment/CommentFormController.php
Overrides EntityFormController::buildEntity().
TermFormController::buildEntity in drupal/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php
Overrides Drupal\Core\Entity\EntityFormController::buildEntity().

File

drupal/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php, line 76
Contains \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->entity;
  $entity_type = $entity
    ->entityType();
  $info = entity_get_info($entity_type);

  // @todo Exploit the Field API to process the submitted entity fields.
  // Copy top-level form values that are entity fields but not handled by
  // field API without changing existing entity fields that are not being
  // edited by this form. Values of fields handled by field API are copied
  // by field_attach_extract_form_values() below.
  $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 fields.
  if (isset($form['#entity_builders'])) {
    foreach ($form['#entity_builders'] as $function) {
      call_user_func_array($function, array(
        $entity_type,
        $entity,
        &$form,
        &$form_state,
      ));
    }
  }

  // Invoke field API for copying field values.
  if ($info['fieldable']) {
    field_attach_extract_form_values($entity, $form, $form_state);
  }
  return $entity;
}