0

I have a question about taxonomy term system path. I have run this code:

function MYMODULE_menu_alter(&$items) {
  unset($items['taxonomy/term/%taxonomy_term']);
  unset($items['taxonomy/term/%taxonomy_term/view']);
  unset($items['taxonomy/term/%taxonomy_term/feed']); // If you want to hide the feed as well.
}

Now I want to know how to reverse this for the future need. How can I set system paths for all taxonomy terms. Thanks in advance.

edit:

Hi David

In first place I have a problem how to forbid anonymous access to all taxonomy terms (eg. mysite/vocabulary/term). I don't want anonymous user to see this pages. I was searching for answer whole day and I found the alter_menu snippet as the only suitable answer, because for now I don't need terms links from outside world.

So, if I put this script in custom module and run once it clears all system paths for all taxonomy tearms (as it can be seen from admin/URl aliases/list). This is good solution, but I don't think the best one. I need a proof that in the future if I will need this system paths, I can rebuild them. I don't know how to do it!?

I have tried to comment that hook_menu_alter snippet but what next I have to do. I mean, system paths will not be automatically rebuilded. Am I right?

Also, i didn't find suitable module to control access to taxonomy terms from outside for anonymous users. Some modules can control that, but my site is using terms thru views and with that modules views are also invisible for anonymous users (eg. Taxonomy Tools module, access part).

1
  • If you want to deny access, better to use hook_menu_alter to add your own access callback to the taxonomy menu paths. Alternatively, override the path with Panels or Views and set access control there. Feb 7 '13 at 22:36
0

The question is a little unclear, to reverse that effect, you would simply delete that hook_menu_alter snippet.

To change the paths to something else, you would use hook_menu and create the relevant menu callbacks.

The last step there would be to change the taxonomy_term entity_uri so it uses your new callback.

i.e redefine taxonomy_term_uri in hook_entity_info_alter

/**
 * Implements hook_entity_info_alter
 */
function mymodule_entity_info_alter(&entity_info){
  $entity_info['taxonomy_term']['uri callback'] = 'mymodule_taxonomy_term_uri';
}

/** 
 * Custom taxonomy_term entity_uri callback
 */
function mymodule_taxonomy_term_uri($term){
  return array(
    'path' => 'mymodule/taxonomy/term/' . $term->tid,
  );
}

Not sure why you'd want to do that though ;)

edit: If you want to deny access, better to use hook_menu_alter to add your own access callback to the taxonomy menu paths. Alternatively, override the path with Panels or Views and set access control there.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.