function hook_field_collection_item_label in Field collection 7
Alter the label for a field collection.
Parameters
FieldCollectionItemEntity $item: The field collection item object.
$host: The host entity of the field collection item.
$field: The field information about the item.
Return value
string A string to represent the label for this item type.
1 invocation of hook_field_collection_item_label()
- FieldCollectionItemEntity::defaultLabel in ./
field_collection.entity.inc - Specifies the default label, which is picked up by label() by default.
File
- ./
field_collection.api.php, line 197 - Contains API documentation and examples for the Field Collection.
Code
function hook_field_collection_item_label($item, $host, $field) {
switch ($item->field_name) {
case 'field_my_first_collection':
$item_wrapper = entity_metadata_wrapper('field_collection_item', $item);
$title = $item_wrapper->field_title
->value();
$author = $item_wrapper->field_author
->value();
return "{$title} by {$author}";
}
}