Hello!
I want to override the output of the page taxomony / term /% for a controlled vocabulary "test_vocab".
I created a module and it wrote:
function mymodule_menu_alter(&$items) {
$items['taxonomy/term/%']['access callback'] = 'mymodule_access_term_pages';
$items['taxonomy/term/%']['page callback'] = 'mymodule_taxonomy_term_page';
$items['taxonomy/term/%']['access arguments'] = array(2);
$items['taxonomy/term/%']['page arguments'] = array(2);
}
function mymodule_access_term_pages($tid) {
return user_access('access content');
}
function mymodule_taxonomy_term_page($tid) {
$term = taxonomy_term_load($tid);
$vocabulary = taxonomy_vocabulary_load($term->vid);
switch($vocabulary->machine_name) {
case 'test_vocab':
// Returns a page themed by mymodule.
return mymodule_taxonomy_render($tid);
default:
// Returns the default term page provided by taxonomy module.
module_load_include('inc', 'taxonomy', 'taxonomy.pages');
return taxonomy_term_page($tid);
}
}
function mymodule_taxonomy_render($tid){
$output = 'HELLO, WORLD!!!';
}
When I check my page taxomony / term /%, containing the terms of my vocabulary, all work fine - shows "HELLO, WORLD !!!".
But if I look at the terms of another vocabulary, it displays:
EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in function entity_extract_ids() (line 7391 in file /var/www/portal/public/includes/common.inc).
I modify entity_extract_ids in common.inc
function entity_extract_ids($entity_type, $entity) {
$info = entity_get_info($entity_type);
// Objects being created might not have id/vid yet.
$id = isset($entity->{$info['entity keys']['id']}) ? $entity->{$info['entity keys']['id']} : NULL;
$vid = ($info['entity keys']['revision'] && isset($entity->{$info['entity keys']['revision']})) ? $entity->{$info['entity keys']['revision']} : NULL;
if (!empty($info['entity keys']['bundle'])) {
// Explicitly fail for malformed entities missing the bundle property.
if (!isset($entity->{$info['entity keys']['bundle']}) || $entity->{$info['entity keys']['bundle']} === '') {
print_r($info['entity keys']);
echo '</br>entity = "' . $entity . '"';
throw new EntityMalformedException(t('Missing bundle property on entity of type @entity_type.', array('@entity_type' => $entity_type)));
And i get:
Array
(
[id] => tid
[bundle] => vocabulary_machine_name
[label] => name
[revision] =>
)
entity = "91"
This is a bug Drupal? Or am I doing something wrong?
Comments
Comment #0.0
fexmusicmutuz commentedadd code tag
Comment #0.1
fexmusicmutuz commentedcode to php tag
Comment #1
fexmusicmutuz commentedEverything works fine, I just made a mistake: (
as a function of mymodule_taxonomy_term_page had to write return taxonomy_term_page ($term), rather than return taxonomy_term_page ($tid);
Comment #1.0
fexmusicmutuz commentedfix error