User login

Hook theme registry alter issue takes away entire site theme

Searched words: 
page.tpl.php

The entire theme disappearing issue has an identified culprit.

(It was sort of cute– devel still printed the query log, but that's all we got for each page.)

First I commented out scf.module's implementation of hook_theme(), but visiting the admin/build/modules and admin/build/themes pages didn't bring it back.

Then I commented out the implementation of hook_theme_registry_alter(), and that brought the site back (and with it, the ability to see the warning messages).

First, the guilty function, that appears to only work with the scf stub theme:

<?php
/**
* Implementation of hook_theme_registry_alter().
*/
function scf_theme_registry_alter(&$theme_registry) {
  // names of hooks handled by scf
  $theme_hooks = array(
    'block',
    'comment',
    'comment_wrapper',
    'node',
    'forums',
    'forum_list',
    'forum_topic_list',
    'forum_icon',
    'forum_submitted',
//    'forum_topic_navigation'  (not currently handled)
    'page',
  );
  // Get the path to this module
  $path = drupal_get_path('module', 'scf') . '/theme';
  // Add the path paths
  foreach ($theme_hooks AS $theme_hook) {
    if (!scf_au_stringpart_in_array($theme_registry[$theme_hook]['theme paths'],
'themes')) {
      // if there is no path with 'themes' in the theme registry
      // then replace the template path with our module path
      // if we add this when the theme is in charge, it throws errors
      // that oddly mungle the theme path plus the module template path
      // but without a theme directory being called first, this works
      // and this really is necessary for everything above
     
      // This just gets crazier and crazier.  Must be wrong, but it works.
      // Transform _ in hook to - to match template naming scheme
      $tpl = strtr($theme_hook, '_', '-');

      $theme_registry[$theme_hook]['template'] = $path . '/' . $tpl;
    }
    array_unshift($theme_registry[$theme_hook]['theme paths'], $path);
//  setting the specific chosen path isn't necessary   
//  $theme_registry[$theme_hook]['theme path'] = $path . '/' . $theme_hook;
    // this isn't documented, but it has proven necessary for page at least
  }
}
?>

And now the error message:

* warning: include(./themes/garland/profiles/scf/modules/scf/theme/page.tpl.php) [function.include]: failed to open stream: No such file or directory in /RCS/agaric/agaric-sites/scf/includes/theme.inc on line 979.
* warning: include() [function.include]: Failed opening './themes/garland/profiles/scf/modules/scf/theme/page.tpl.php' for inclusion (include_path='.:/Applications/xampp/xamppfiles/lib/php') in /RCS/agaric/agaric-sites/scf/includes/theme.inc on line 979.

Returning (and moving and focusing) my commented out code seems to have fixed it.

<?php
/**
* Implementation of hook_theme_registry_alter().
*/
function scf_theme_registry_alter(&$theme_registry) {
  // names of hooks handled by scf
  $theme_hooks = array(
    'block',
    'comment',
    'comment_wrapper',
    'node',
    'forums',
    'forum_list',
    'forum_topic_list',
    'forum_icon',
    'forum_submitted',
//    'forum_topic_navigation'  (not currently handled)
    'page',
  );
  // Get the path to this module
  $path = drupal_get_path('module', 'scf') . '/theme';
  // Add the path paths
  foreach ($theme_hooks AS $theme_hook) {
    if (!scf_au_stringpart_in_array($theme_registry[$theme_hook]['theme paths'],
'themes')) {
      // if there is no path with 'themes' in the theme registry
      // then replace the template path with our module path
      // if we add this when the theme is in charge, it throws errors
      // that oddly mungle the theme path plus the module template path
      // but without a theme directory being called first, this works
      // and this really is necessary for everything above
     
      // This just gets crazier and crazier.  Must be wrong, but it works.
      // Transform _ in hook to - to match template naming scheme
      $tpl = strtr($theme_hook, '_', '-');

      $theme_registry[$theme_hook]['template'] = $path . '/' . $tpl;
    }
    array_unshift($theme_registry[$theme_hook]['theme paths'], $path);
//  setting the specific chosen path isn't necessary   
  }
  $theme_registry[$theme_hook]['theme path'] = $path . '/' . 'page'; // $theme_hook;
    // this isn't documented, but it has proven necessary for page at least
}
?>

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Internal paths in single or double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or path. Paths to files in single or double quotes, written as "files:somefile.ext", for example, are replaced with the appropriate URL that can be used to download the file.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.