The doc for theme_get_registry() does not match its code; the function does not create the registry and cache it.

/**
 * Retrieve the stored theme registry. If the theme registry is already
 * in memory it will be returned; otherwise it will attempt to load the
 * registry from cache. If this fails, it will construct the registry and
 * cache it.
 */
function theme_get_registry($registry = NULL) {
  static $theme_registry = NULL;
  if (isset($registry)) {
    $theme_registry = $registry;
  }

  return $theme_registry;
}
CommentFileSizeAuthor
#1 theme_get_registry-232345-1.patch1.48 KBfloretan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

floretan’s picture

Status: Active » Needs review
FileSize
1.48 KB

This code/documentation conflict actually pointed to some poorly structured code. The private function _theme_set_registry() makes a call to theme_get_registry($registry) to store data in a static variable.

Here's a patch that makes the interaction of these two functions consistent with other setter/getter pairs like drupal_set_message() and drupal_get_message(). When the code is clean, documenting it becomes much easier.

This patch doesn't modify the behavior of the code, but it makes it more obvious that if theme_get_registry() is called before the registry has been built or retrieved from the cache, it will return a NULL value. Is this really the desired behavior or should we ensure that the theme registry exists in memory whenever theme_get_registry() gets called?

Robin Monks’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, the registry SimpleTests under "System" also ran without issue, "11 passes, 0 fails, 0 exceptions".

Robin

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

iimitk’s picture

The documentation of _theme_set_registry() in flobruit's patch says:

+ *   A registry array as returned by _theme_build_registry()
+ * @return 
+ *   The theme registry array stored in memory
  */

I think it should point out to _theme_load_registry() because if the theme registry is already cached it will not be returned by _theme_build_registry().