In a module, I have defined a custom field. Using hook_field_formatter_info() and hook_field_formatter_view(), I can manage the display of every item (value) within that field. I want to allow the use of multiple values of this field.
How can I add extra HTML to this 'collection'? Programmatically, from within my module.
For example, let's say my module adds a 'fruit' field, that allows me to enter its name and its color. Now, I'd like to display this as such:
Name: Strawberry. Color: Red
Name: Orange. Color: Orange
Name: Lime. Color: Green
<some>Extra Html</some>
How to add that extra last line?
I can find references to hooks that should do it, but I simply don't understand how to tie all these pieces of information together. I suspect I have to work with:
hook_field_prepare_view https://api.drupal.org/api/drupal/modules%21field%21field.api.php/function/hook_field_prepare_view/7
I also found this resource suggesting these hooks: http://www.failover.co/blog/drupal-7-custom-field-formatter-hooks-overview
and that I should manipulate the render array.
And I tried just adding an extra element to the array, an extra delta:
$element[] = array(
'#type' => 'markup',
'#markup' => "Test HTML"
);
But is seems to get ignored by Drupal
hook_field_formatter_view()
? You have access to the full render array containing all the field deltas, so it would seem like the most logical place to do so$element['footer']['#markup'] = 'foo';