On my Drupal 7 site, I have a module which needs to determine the type of page being shown / being loaded.
I first implemented hook_entity_view_alter. Doing this:
/**
* Implements hook_entity_view_alter
*/
/*
function rsc_search_entity_view_alter(&$build, $type)
{
echo "$type <br/>";
echo $build['#entity_type'].'<br/>';
}
shows the info I need, so I know that the hook is being called. BUT, on taxonomy term pages, nothing shows up, although there should be an entity with type 'taxonomy_term'. See the last few lines of code at: http://api.drupal.org/api/drupal/modules!taxonomy!taxonomy.module/function/taxonomy_term_view/7
So I tried the next thing, which is implementing hook_taxonomy_term_view_alter to catch those term pages:
/**
* Implements hook_taxonomy_term_view_alter
*/
function rsc_search_taxonomy_term_view_alter(&$build)
{
$var = $build;
$build['extra'] = array('#markup'=>'nothing');
echo 'tax_term';
if ($build['#view_mode']=='full')
{
echo '<pre>';
var_dump($build);
echo '</pre>';
}
}
This, however, NEVER DOES ANYTHING!
As far as I understand the documentation, I * used the correct function names * used the correct function parameters * remembered to clear the caches
Any ideas on what went wrong? Why can't I implement taxonomy alteration hooks?
EDIT
Clive asked whether I am using views taxonomy. But I am using a custom taxonomy page, which still calls taxonomy_term_view
function CSL_custom_admin_menu_alter(&$items)
{
$items['taxonomy/term/%taxonomy_term'] = array(
'title' => 'Taxonomy term',
'title callback' => 'taxonomy_term_title',
'title arguments' => array(2),
'page callback' => 'taxonomy_term_page',
'page arguments' => array(2),
'access arguments' => array('access content'),
'file' => 'taxonomy.pages.inc',
'file path' => 'sites/all/modules/CSL_custom_admin'
);
}
Here is an extract from my taxonomy.pages.inc:
/**
* Menu callback; displays all nodes associated with a term.
*
* @param $term
* The taxonomy term.
* @return
* The page content.
*/
function taxonomy_term_page($term)
{
drupal_set_breadcrumb(CSL_taxonomy_breadcrumb($term));
drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $term->name);
$subs = CSL_taxonomy_subs_count(taxonomy_get_tree($term->vid, $term->tid, 1));
$nids = CSL_taxonomy_nids($term->tid, TRUE, variable_get('default_nodes_main', 10), ( isset($term->field_enable_sort['und'][0]['value'])&&$term->field_enable_sort['und'][0]['value'] ) || ( isset($term->field_toelaat_sorteer['und'][0]['value'])&&$term->field_toelaat_sorteer['und'][0]['value'] ) );
$build = array();
// Add term heading if the term has a description
if (!empty($term->description))
{
$build['term_heading'] = array(
'#prefix' => '<div class="term-listing-heading">',
'#suffix' => '</div>',
'term' => taxonomy_term_view($term, 'full'),
'#weight' => 1
);
}
if ($nids && $subs)
{
$build['subterms'] = array
(
'#prefix' => '<div class="taxonomy-subterms-wrapper">',
'#suffix' => '</div>',
'subterms' => array
(
'#theme' => 'CSL_custom_admin_taxsubstable',
'#rows' => $subs,
'#weight' => 2
)
);
$build['nodes'] = array
(
'#prefix' => '<div class="taxonomy-nodes-wrapper">',
'#suffix' => '</div>',
'nodes' => node_view_multiple(node_load_multiple($nids)),
'#weight' => 3
);
}
else if ($nids) // no subs
{
$build['subterms'] = array
(
'#prefix' => '<div class="taxonomy-subterms-wrapper">',
'#suffix' => '</div>',
'#markup' => '<strong>'.t('This term has no subcategories.').'</strong>',
'#weight' => 2
);
$build['nodes'] = array
(
'#prefix' => '<div class="taxonomy-nodes-wrapper">',
'#suffix' => '</div>',
'nodes' => node_view_multiple(node_load_multiple($nids)),
'#weight' => 3
);
}
else if ($subs) // no nids
{
$build['subterms'] = array
(
'#prefix' => '<div class="taxonomy-subterms-wrapper">',
'#suffix' => '</div>',
'subterms' => array
(
'#theme' => 'CSL_custom_admin_taxsubstable',
'#rows' => $subs
),
'#weight' => 2
);
$build['nodes'] = array
(
'#prefix' => '<div class="taxonomy-nodes-wrapper">',
'#suffix' => '</div>',
'#markup' => '<strong>'.t('Refer to one of the subcategories for articles.').'</strong>',
'#weight' => 3
);
}
else // nothing to see
{
$build['nodes'] = array
(
'#prefix' => '<div class="taxonomy-nodes-wrapper">',
'#suffix' => '</div>',
'#markup' => '<strong>'.t('There is currently no content in this category.').'</strong>',
'#weight' => 3
);
}
$build['pager_top'] = array(
'#theme' => 'pager',
'#weight' => -5
);
$build['pager_bottom'] = array(
'#theme' => 'pager',
'#weight' => 5
);
return $build;
}
I know my module names should not start with a capital letter (CSL_), but that should not affect anything here.