When creating a new entity of a entity type that supports bundles and the entity creation form for that entity type lets the user select the bundle for that entity entity_form_submit_build_entity() fails.
This happens, because it invokes entity_extract_ids to retrieve the bundle property when it hasn't been set yet. This can easily be solved by populating the bundle property of that entity before continuing.
function entity_form_submit_build_entity($entity_type, $entity, $form, &$form_state) {
$info = entity_get_info($entity_type);
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
// 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, $bundle)) : $form_state['values'];
foreach ($values_excluding_fields as $key => $value) {
$entity->$key = $value;
}
// Invoke all specified builders for copying form values to entity properties.
if (isset($form['#entity_builders'])) {
foreach ($form['#entity_builders'] as $function) {
$function($entity_type, $entity, $form, $form_state);
}
}
// Copy field values to the entity.
if ($info['fieldable']) {
field_attach_submit($entity_type, $entity, $form, $form_state);
}
}
Comments
Comment #1
fubhy commentedComment #3
berdirAll different in 8.x, moving back to 7.x ;)