Skip to content

Instantly share code, notes, and snippets.

@waako
Forked from rupertj/merge item_list items.php
Created November 29, 2012 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waako/4170921 to your computer and use it in GitHub Desktop.
Save waako/4170921 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',
)
);
$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) {
$term_name = $term['taxonomy_term']->name;
// Take the taxonomy term name, make lowercase and replace space with a dash to use as a css class
$term_css = strtolower(str_replace(" ", "-", $term_name));
// Two values that need to be merged into one item
if ($term['taxonomy_term']->name == 'Easily doubled') {
$easily_doubled_key = $key;
} else if ($term_name == 'Easily halved') {
$easily_halved_key = $key;
}
$variables['planning']['#items'][$key] = array(
'data' => t('<i class="icon-small icon-' . $term_css . '"></i>' . $term_name),
'class' => array('class' => $term_css,),
);
}
if ($easily_doubled_key && $easily_halved_key) {
$term_name = t('Easily doubled<br/>Easily halved');
$variables['planning']['#items'][$easily_doubled_key] = array(
'data' => t('<i class="icon-small icon-easily"></i>' . $term_name),
'class' => array('class' => 'easily',),
);
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