MoritzLost Posted May 12, 2020 Posted May 12, 2020 Sorry for the convoluted title. I have a problem with Process modules that define a custom page using the page key through getModuleInfo (as demonstrated in this excellent tutorial by @bernhard). Those pages are created automatically when the module is installed. The problem is that the title of the page only gets set in the current language. That's not a problem if the current language (language of the superuser who is installing the module) is the default language; if it isn't, the Process page is missing a title in the default language. This has the very awkward effect that a user using the backend in the default language (or any other language) will see an empty entry in the setup menu: This screenshot comes from my Cache Control module which includes a Process page. Now I realize the description sounds obscure, but for us it's a common setup: We a multiple bilingual sites where the default language is German and the second language is English. While the clients use the CMS in German, as a developer I prefer the English interface, so whenever I install a Process module I get this problem. As a module author, is there a way to handle this situation? I guess it would be possible to use post-installation hooks or create the pages manually, but I very much prefer the declarative approach. The page title is already translatable (through the __ function), but of course at the time of installation there is no translation, and as far as I'm aware it's not possible to ship translations with a module so they are used automatically. Could this situation be handled better in the core? I would prefer if the module installation process would always set the title of the Process page in the default language, instead of the language of the current user. 1
kongondo Posted May 12, 2020 Posted May 12, 2020 (edited) 32 minutes ago, MoritzLost said: is there a way to handle this situation? I still do this the old fashioned way ?. I have never gotten round to using the page key syntax. Instead, I do this, i.e. create my module's page title (and other stuff if required) in the ___install() routine. So, this could be a workaround in your case. Here's an example from my Blog module public function ___install() { $pages = $this->wire('pages'); // create Blog Admin page $page = $pages->get('template=admin, name='.self::PAGE_NAME); if (!$page->id) { $page = new Page(); $page->template = 'admin'; $page->parent = $pages->get($this->wire('config')->adminRootPageID); $page->title = 'Blog'; $page->name = self::PAGE_NAME; $page->process = $this; $page->save(); // tell the user we created this page $this->message("Created Page: {$page->path}"); } // we create the permission blog to limit access to the module $permission = $this->permissions->get('blog'); if (!$permission->id) { $p = new Permission(); $p->name = 'blog'; $p->title = $this->_('View Blog Page'); $p->save(); // tell the user we created this module's permission $this->message("Created New Permission: blog"); } // save initial module configurations $this->wire('modules')->saveModuleConfigData($this, self::configDefaults()); } In other modules I even call external scripts from within install(). Edited May 12, 2020 by kongondo 1
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