hook_theme_registry_alter
should provide a second parameter containing the name of the theme that we are currently building the registry for. In many cases this is not required but I just recently ran across one where it indeed is. I am aware of the fact, that in 99.99% of the cases this is identical to the global $theme_key
but since the functions that invoke hook_theme_registry_alter
are also called with the theme name as a parameter it is not unlikely that this code might be called with a different theme name than the currently active theme (for example by a contrib module).
@see: http://api.drupal.org/api/drupal/includes--theme.inc/function/_theme_bui...
Comments
Comment #1
dvessel CreditAttribution: dvessel commentedI think you're confused about how the alter hooks interact with modules and themes.
If you want to target a specific theme then try using the global $theme (not $theme_key since that can change in various conditions). The $theme global will always be specific to the theme that rendered the current page.
But I do see how it can be useful to have that parameter for easy access. Bumping to 8 since it's an api change.
Comment #2
lauriiiThis is a feature that could be added in a minor version of Drupal 8. However I still don't understand, what is the use case for altering theme registry for specific theme only from a module? I don't think such thing should be possible since modules cannot depend on theme. If you use hook_theme_registry_alter inside theme it will be run only for the theme where the alter is in.
Comment #5
joelpittetIn Drupal 8 we can get the current active theme with
\Drupal::theme()->getActiveTheme()->getName()
Closing to triage the issue queue, reopen if you feel this still needs to be addressed. If so please address questions from #2
Comment #6
donquixote CreditAttribution: donquixote as a volunteer commentedThe idea is not to target a specific theme name from the module, but to do alterations depending on information found in or for the theme being processed.
Examples:
None of these hooks hardcode a specific theme name.
In addition, themes can use this hook to alter their own theme registry. In this case it would be ok to hardcode the theme name.
I am switching to "Active" again.
Comment #7
donquixote CreditAttribution: donquixote as a volunteer commentedMy previous comment was about Drupal 7.