Theme hook in custom module not found after clear cache

Created on 17 October 2018, over 6 years ago
Updated 31 May 2023, over 1 year ago

i have this simple controller:

class PageController extends ControllerBase {
  
    public function registerPage() {
		
		return [
			'#theme' => 'gey_user_agent__register_page',
			'#content' => array(),
			'#attributes' => [],
			'#cache' => array(
					'max-age' => 0
			)
    	];
	}
	
}

and the theme hook

function gey_user_agent_theme($existing, $type, $theme, $path) {
    return array(
        'gey_user_agent__register_page' => array(
            'variables' => array('content' => NULL),
        ),
    );
}

when i install the module i have no problem. i can see the content of the template.
after clear cache i get this error.

Theme hook Theme hook gey_user_agent not found.

After reinstall works fine till i clear the cache.

Which is the problem?

💬 Support request
Status

Active

Version

9.5

Component
Theme 

Last updated 3 days ago

Created by

🇮🇹Italy trickfun

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom very_random_man

    I've just run into this issue too on Drupal 9.5.9. I created a custom entity module with drush generate and later added hook_theme and template_preprocess.

    If I use drush cr, everything works as expected. If I use 'Flush all caches' in the admin menu, the module's theme entry is missing from the theme registry. My temporary (and very hacky) workaround is to detect if it's missing from the registry in hook_theme_registry_alter and then put it back. Not ideal but needs must. ;-)

  • 🇬🇧United Kingdom aaron.ferris

    Weird, both admin_toolbar_tools flushAll()and drush cr call drupal_flush_all_caches()

    If anything it's drush cr that has more going on....

  • 🇬🇧United Kingdom very_random_man

    I noticed one of the guys above had a workaround to rename and reinstall the module. In my case i didn't create the module-name.module file until after I'd been using my module for a while. I wonder if that is connected? I seem to remember it wouldn't register the module file until I did a drush cr rather than an admin toolbar Flush All Caches. Maybe there's a clue in that?

  • 🇦🇷Argentina andreses

    Solution:

    In fact, the problem is when the module is installed without the "module" file and it is added later. This causes the "module" file to not be registered. So when clearing the cache from the interface the "module" file is not consulted. The solution, change the "info.yml" of the module. This will cause good old Drupal to detect the change and rebuild the record and thus read the "module" file.

    What type of change?, for example the version, if you have:
    version: '1.0.0'
    give it for example:
    version: '1.0.1'
    tested on Drupal 9.5 and 10

  • 🇳🇱Netherlands idebr

    Clarifying issue title

  • 🇨🇴Colombia diegoluisr

    I needed to reintall the module, it is not possible in all cases, but is a solution.

Production build 0.71.5 2024