Commit d638900d authored by drunkenmonkey's avatar drunkenmonkey Committed by Ra Mänd
Browse files

Issue #2489142 by drunken monkey, mihai_brb, julia.klimovsky: Add entity...

Issue #2489142 by drunken monkey, mihai_brb, julia.klimovsky: Add entity type-specific versions of the "Host entity" property
parent d2e9b0f7
......@@ -24,6 +24,26 @@ class FieldCollectionItemMetadataController extends EntityDefaultMetadataControl
'required' => TRUE,
);
// Also add type-specific host entity references for all entity types that
// have at least one field collection field.
$field_collection_fields = field_read_fields(array('type' => 'field_collection'));
$entity_types = entity_get_info();
foreach (field_info_instances() as $entity_type => $bundles) {
foreach ($bundles as $bundle => $fields) {
if (array_intersect_key($fields, $field_collection_fields)) {
$args = array('@type' => $entity_types[$entity_type]['label']);
$properties["host_entity_$entity_type"] = array(
'label' => t('Host entity (@type)', $args),
'type' => $entity_type,
'description' => t('The @type containing the field collection field (empty if this field collection is attached to an item of a different type).', $args),
'getter callback' => 'field_collection_item_get_specific_type_host_entity',
'computed' => TRUE,
);
break;
}
}
}
return $info;
}
......
......@@ -1835,6 +1835,17 @@ function field_collection_item_get_host_entity($item) {
return entity_metadata_wrapper($item->hostEntityType(), $item->hostEntity());
}
/**
* Entity property info getter callback for the host entity property.
*/
function field_collection_item_get_specific_type_host_entity($item, array $options, $name) {
// These properties' machine names have the form "host_entity_TYPE".
if (substr($name, 0, 12) !== 'host_entity_') {
return NULL;
}
return $item->hostEntityType() === substr($name, 12) ? $item->hostEntity() : NULL;
}
/**
* Entity property info getter callback for the field collection items.
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment