Drupal - Whats the proper way to preprocess field collection items to add first and last class names?
You would normally do this in MYTHEME_preprocess_field_collection_item(), but field collection items don't have their own preprocess. Fortunately, they're entities, so you can use entity preprocess to create your own field collection preprocess function:
/**
* Implements template_preprocess_entity().
*/
function MYTHEME_preprocess_entity(&$variables, $hook) {
$function = 'MYTHEME_preprocess_' . $variables['entity_type'];
if (function_exists($function)) {
$function($variables, $hook);
}
}
/**
* Field Collection-specific implementation of template_preprocess_entity().
*/
function MYTHEME_preprocess_field_collection_item(&$variables) {
$variables['classes_array'][] = 'your-class-here';
// Plus whatever other preprocessing you want to do.
}
In Drupal 8 the preprocess function exists without having to add one:
/**
* Implements hook_preprocess_field_collection_item().
*/
function mymodule_preprocess_field_collection_item(array &$vars, $hook) {
//dpm($vars);
}