Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
drupal.org
field_collection
Commits
0ef51d59
Commit
0ef51d59
authored
Jan 06, 2015
by
KeyboardCowboy
Committed by
Joel Muzzerall
Jan 06, 2015
Browse files
Issue #1617792 by KeyboardCowboy: Support for entityreference / setting the entity label
parent
bb4c9813
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
3 deletions
+32
-3
field_collection.api.php
field_collection.api.php
+27
-1
field_collection.module
field_collection.module
+5
-2
No files found.
field_collection.api.php
View file @
0ef51d59
...
...
@@ -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
*/
field_collection.module
View file @
0ef51d59
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment