Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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;
}
Comment | File | Size | Author |
---|---|---|---|
#1 | theme_get_registry-232345-1.patch | 1.48 KB | floretan |
Comments
Comment #1
floretan CreditAttribution: floretan commentedThis 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?
Comment #2
Robin Monks CreditAttribution: Robin Monks commentedLooks good, the registry SimpleTests under "System" also ran without issue, "11 passes, 0 fails, 0 exceptions".
Robin
Comment #3
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #5
iimitk CreditAttribution: iimitk commentedThe documentation of
_theme_set_registry()
in flobruit's patch says: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()
.