function _multifield_create_stub_entity_with_subfield_data in Multifield 7.2
Same name and namespace in other branches
- 7 multifield.field.inc \_multifield_create_stub_entity_with_subfield_data()
4 calls to _multifield_create_stub_entity_with_subfield_data()
- multifield_field_delete in ./
multifield.field.inc - Implements hook_field_delete().
- multifield_field_insert in ./
multifield.field.inc - Implements hook_field_insert().
- multifield_field_presave in ./
multifield.field.inc - Implements hook_field_presave().
- multifield_field_update in ./
multifield.field.inc - Implements hook_field_update().
File
- ./
multifield.field.inc, line 856 - Field integration for the Multifield module.
Code
function _multifield_create_stub_entity_with_subfield_data($machine_name, array &$items, array $original_items, $parent_entity_type, $parent_entity, $langcode) {
// Create a stub clone of the parent entity.
$stub = entity_create_stub_entity($parent_entity_type, entity_extract_ids($parent_entity_type, $parent_entity));
if (!empty($parent_entity->original)) {
$stub->original = entity_create_stub_entity($parent_entity_type, entity_extract_ids($parent_entity_type, $parent_entity->original));
}
foreach (multifield_type_get_subfields($machine_name) as $subfield_name) {
$stub->{$subfield_name} = array(
$langcode => array(),
);
if (isset($stub->original)) {
$stub->original->{$subfield_name} = array(
$langcode => array(),
);
}
foreach ($items as $delta => $item) {
if (isset($item[$subfield_name][LANGUAGE_NONE][0])) {
$stub->{$subfield_name}[$langcode][$delta] =& $item[$subfield_name][LANGUAGE_NONE][0];
}
if (isset($stub->original) && isset($original_items[$delta][$subfield_name][LANGUAGE_NONE][0])) {
$stub->original->{$subfield_name}[$langcode][$delta] = $original_items[$delta][$subfield_name][LANGUAGE_NONE][0];
}
}
$stub->{$subfield_name}[$langcode] = array_filter($stub->{$subfield_name}[$langcode]);
if (isset($stub->original)) {
$stub->original->{$subfield_name}[$langcode] = array_filter($stub->original->{$subfield_name}[$langcode]);
}
}
return $stub;
}