Overrides EntityFormController::buildEntity().
Overrides EntityFormController::buildEntity
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;
}