Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current page/url in a hook

In hook_css_alter, I want to disable style-sheets on specific pages. Was ok for the front page requirement with following snippet:

function morin_css_alter(&$css) {
  if(drupal_is_front_page()){
    foreach ($css as $data => $item) {
      unset($css[$data]);
    }
  }
}

Now I need to remove specific styles on a photo-album page. I have thought of a few ways to do this, but I'd like to do it the drupal way.

The closest function I have found to do this is drupal_get_destination() , I don't think it's meant for this but it does return the current path in an array, as shown by the following snippet added in css_alter hook.

echo " PATH = " . var_dump(drupal_get_destination());

Output: PATH = array(1) { ["destination"]=> string(6) "photos" }

Is this the recommended way of getting the path from inside a function/hook, or is there some variable in global namespace I should use instead?

like image 970
stefgosselin Avatar asked Jan 21 '23 08:01

stefgosselin


1 Answers

You want http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/request_path/7.

For Drupal 6, one has to use $_GET['q'].

like image 111
Berdir Avatar answered Mar 07 '23 17:03

Berdir