Jump to content

Titles of pages for Process modules may be missing when installed in non-default languages


MoritzLost
 Share

Recommended Posts

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:

1317970094_Screenshot2020-05-12at15_34_17.png.872136a1bae40e59de313ed2d8654eac.png

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.

  1. 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.
  2. 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.
  • Like 1
Link to comment
Share on other sites

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 by kongondo
  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...