Commit 0ef51d59 authored by KeyboardCowboy's avatar KeyboardCowboy Committed by Joel Muzzerall
Browse files

Issue #1617792 by KeyboardCowboy: Support for entityreference / setting the entity label

parent bb4c9813
......@@ -164,6 +164,32 @@ function hook_field_collection_item_view_alter($build) {
}
}
/**
* Alter the label for a field collection.
*
* @param FieldCollectionItemEntity $item
* The field collection item object.
* @param $host
* The host entity of the field collection item.
* @param $field
* The field information about the item.
*
* @return $label
* A string to represent the label for this item type.
*/
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}";
}
}
/**
* @}
*/
\ No newline at end of file
*/
......@@ -261,12 +261,15 @@ class FieldCollectionItemEntity extends Entity {
* Specifies the default label, which is picked up by label() by default.
*/
public function defaultLabel() {
// @todo make configurable.
if ($this->fetchHostDetails()) {
$field = $this->fieldInfo();
$label = $this->translatedInstanceLabel();
$host = $this->hostEntity();
if ($field['cardinality'] == 1) {
if ($new_label = module_invoke_all('field_collection_item_label', $this, $host, $field, $label)) {
return array_pop($new_label);
}
elseif ($field['cardinality'] == 1) {
return $label;
}
elseif ($this->item_id) {
......
Markdown is supported
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