Answers:
通常,您可以在MYTHEME_preprocess_field_collection_item()中执行此操作,但是字段收集项没有自己的预处理。幸运的是,它们是实体,因此您可以使用实体预处理来创建自己的字段集合预处理函数:
/**
* 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.
}