我做了尽职调查,但无法在任何地方找到答案。我试图在字段集合中弹出一个数组,然后内爆它。这是我的代码,它不起作用。任何帮助表示赞赏。
/**
* 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) {
// Return a comma separated list of donors
if ($variables['view']->current_display != 'bookplates_landing_page') {
if ($variables['#field_name'] == 'field_collection_donor') {
}
// nothing below here works
// render text for single donor
if (count($variables['row']->field_field_collection_donor) == 1) {
$variables['output'] = $variables['#field_name']->last_render_text;
}
else {
// get all the donors
$donors = array();
foreach ($variables['row']->field_field_collection_donor as $donor) {
$donors[] = $donor['raw']['safe_value'];
}
// append the last donor with an "and" before it
$donor_last = array_pop($donors);
$variables['output'] = implode(', ', $donors) . " and " . $donor_last;
}
}
}