Skip to content

Instantly share code, notes, and snippets.

@waako
Created November 29, 2012 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save waako/4170173 to your computer and use it in GitHub Desktop.
Save waako/4170173 to your computer and use it in GitHub Desktop.
merge two items to be rendered in item_list
$variables['planning'] = array(
'#theme' => 'item_list',
'#items' => array(),
'#attributes' => array(
'class' => 'icons-info unstyled floated',
)
);
foreach(array_merge($variables['field_bbcgf_planning'], $variables['field_bbcgf_diet'], $variables['field_bbcgf_healthy']) as $taxon_term_field) {
$term_name = $taxon_term_field['taxonomy_term']->name;
// Two values that need to be merged into one item
if ($term_name == t('Easily doubled') && $term_name == t('Easily halved')) {
$term_name = t('Easily doubled<br/>Easily halved');
}
$variables['planning']['#items'][] = array(
'data' => t('<i class="icon-small icon-' . $term_css . '"></i>' . $term_name),
'class' => array('class' => $term_css,),
);
}
@rupertj
Copy link

rupertj commented Nov 29, 2012

$variables['planning'] = array(
'#theme' => 'item_list',
'#items' => array(),
'#attributes' => array(
'class' => 'icons-info unstyled floated',
)
);

$all_terms = array_merge($variables['field_bbcgf_planning'], $variables['field_bbcgf_diet'], $variables['field_bbcgf_healthy']);

$easily_doubled_key = null;
$easily_halved_key = null;

foreach ($all_terms as $key => $term) {

// Two values that need to be merged into one item
if ($term['taxonomy_term']->name == 'Easily doubled') {
$easily_doubled_term = $term;
$easily_doubled_key = $key;
} else if ($term_name == 'Easily halved') {
$easily_halved_term = $term;
$easily_halved_key = $key;
}

$variables['planning']['#items'][$key] = array(
'data' => t('' . $term_name),
'class' => array('class' => $term_css,),
);
}

if ($easily_doubled_key && $easily_halved_key) {
$easily_doubled_term = $all_terms[$easily_doubled_key];
$easily_halved_term = $all_terms[$easily_halved_key];

$term_name = t('Easily doubled
Easily halved');

$variables['planning']['#items'][$easily_doubled_key] = array(
'data' => t('' . $term_name),
'class' => array('class' => $term_css,),
);

unset($variables['planning']['#items'][$easily_halved_key];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment