Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I need to make changes to several admin pages, instead of conditionally tests for the page/node (ie: User, Appearance, Views admin pages right now) can I override each using more specific theme functions?

MYTHEME_preprocess_page_admin_user
MYTHEME_preprocess_page_admin_views
MYTHEME_preprocess_page_admin_appearance

Is this possible? It's the themeing function not the template TPL I need to execute as I am re-structuring some list items in each -- not really changing the markup per se.

Alex

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

Out of the box, Drupal won't do this. You can do something like this, though:

function MYTHEME_preprocess_page(&$variables) {
  $parts = explode('/', request_path());  
  $subhook = __FUNCTION__;

  foreach ($parts as $part) {
    $subhook .= '__' . $part;

    if (function_exists($subhook)) {
      $subhook($variables);
    }
  }
}

This is untested (it may need some tweaking), but it will build up function names based on the request_path(). So, the idea is that if the URL is http://example.com/foo/bar/bar, it will check for

  • MYTHEHE_preprocess_page__foo()
  • MYTHEHE_preprocess_page__foo__bar()
  • MYTHEHE_preprocess_page__foo__bar__baz()

and call each, in sucession, passing in the $variables.

As this will call functions based on user input, you will want to think about some logic to prevent malicious activity, such as only doing it for certain paths, etc.

Just note, that if you are doing this to the admin pages, then you need to do this in the admin theme you have defined for your site, and not the main theme.

I don't normally do this with the preprocess page hooks, but I use something similar for the node ones based on content type and view mode.

share|improve this answer
    
This is kind of what I have done but your solution is far more dynamic - I like it :) Although I was kind of hoping for a built in solution if someone else has tried this and it works thats good enough for me, thanks again :) –  Alex.Barylski Feb 22 at 5:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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