adrian Posted October 23 Posted October 23 Has anyone figured out a reliable way to add a namespace to a module without resulting in a very stubborn error like: Class "WireData" not found Seems like the only reliable way is to uninstall and then install again, but this is kinda of impossible to do once you've already updated the files, so you need to know to uninstall beforehand. I have had requests to namespace my modules, but I don't want to break people's admin interfaces (and mine for that matter). Thanks!
Robin S Posted Sunday at 09:31 PM Posted Sunday at 09:31 PM @adrian, it might be something that only happens with particularly complex modules, because I think I've added the namespace to a bunch of my earlier modules and never struck that problem. And if I test with a dummy module... <?php class TestModule extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Test Module', 'summary' => 'Test applying namespace', 'version' => '0.1.0', 'autoload' => true, ); } public function ready() { $this->addHookAfter('AdminTheme::getExtraMarkup', $this, 'doSomething'); } protected function doSomething(HookEvent $event) { $parts = $event->return; $parts['masthead'] .= "hello"; $event->return = $parts; } } ...then I can add the namespace without issue. If I remove the namespace from a namespaced module then I get a server error, but that's not something anyone would need to do. Just a guess, but you could try removing the previously compiled module files from /site/assets/cache/FileCompiler/site/ in the upgrade() method to see if that makes a difference. 1
adrian Posted Wednesday at 08:03 PM Author Posted Wednesday at 08:03 PM Thanks @Robin S for taking a look - much appreciated. It seems like a random issue here even with my simplest modules. I have played around with removing those FileCompiler files and DB entries and sometimes it helps and other times not. Sometimes I literally need to remove the namespace so I can uninstall, then add it back and then I can reinstall. I am just worried about breaking the admin for users upgrading my modules. I also wonder if sometimes it matters how the module is upgraded - replacing files directly vs updating via the PW Upgrades module - perhaps it triggers a modules refresh before the module gets to load and potentially break things 🤷
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now