Jump to content

Restrict Multi-Language Branch


Recommended Posts

Hi everyone,

Here's a new module that lets you control whether multi-language support is enabled at the page / branch level, rather than only per template.



This is ideal for a site with repeated branches using the same templates where only some need to be multi-language. I think it is confusing to provide multiple language inputs for fields when they are not required - it just bloats the admin interface for site editors.

I am hoping to expand this module to allow selection of which languages are supported per page/branch, but I am waiting on @ryan's response to this request: https://github.com/processwire/processwire-requests/issues/54 - to me this would be even more powerful if you have a situation where certain branches need some languages and other branches need different languages.

The module config settings shows a summary of the restrictions you have implemented, eg:

Screen Shot 2016-11-25 at 10.44.28 AM.png

This shows that we have started with the home page which disables multi-language on itself and all its children/grandchildren (because "This Page Only" is "False".

Next we have the /report-cards/ page multi-language enabled, but no inheritance (because "This Page Only" is "True").

The only branch below this to have multi-language enabled is Guanabara Bay and all it's children etc will also be enabled. All other report card branches will be disabled because they will inherit directly from the config settings default status.

The Settings tab for each page gives you three options: Inherit, Enabled, Disabled. The screenshots give you an idea of how the Inherit option works and the information it provides based on the status it is inheriting and from where.

Screen Shot 2016-11-25 at 10.49.47 AM.png

Screen Shot 2016-11-25 at 10.46.41 AM.png

Screen Shot 2016-11-25 at 10.48.56 AM.png

My goal for this site was to just enable multi-language support for the Guanabara Bay report card branch of the tree, as well as the home page and the /report-cards/ parent. All other branches have multi-language support disabled which makes content entry much cleaner.

Hope you guys find a good use for it and I'll be sure to update with the ability to define which languages are available on which pages/branches if Ryan comes up with a core solution for changing the returned $languages.

Please let me know if you have any problems / suggestions.


  • Like 19
Link to comment
Share on other sites

Hi everyone,

@Christophe was kind enough to notice that I had mis-spelled "Language" throughout the module, including the name of the repo on Github and the class name. I think I have everything updated correctly now, so if anyone has already installed it, you will unfortunately need to install again. Sorry about that!

  • Like 2
Link to comment
Share on other sites

Just now, Zeka said:

Thank you @adrian for so useful module. 

Glad you like it :)


1 minute ago, Zeka said:

Thank you @adrian for so useful module. 
It would be super great to have opportunity to disable default language for some branches/pages

Perhaps you'd consider adding your support to my feature request: https://github.com/processwire/processwire-requests/issues/54

As far as I can tell there is no way for me to control which languages are displayed at the moment. If Ryan can come up with a core solution that lets me hook and change the results returned by $languages then I think I will be able to incorporate your request into this module. My goal is to have a checkboxes field added to the page edit Settings tab that lets you determine which languages are enabled for the page/branch.

Link to comment
Share on other sites

  • 3 weeks later...
2 minutes ago, adrianmak said:

I updated the module. But the mentioned problem still exists.

Even though  multilanguage is disabled on a page, but multilanguage fields are still showing

Sorry about this. Can you please post the contents of the data field on the RestrictMultiLanguageBranch row of the PW modules db table?

Link to comment
Share on other sites

Thanks - unfortunately it looks fine!

I don't suppose there is any chance I can get access to this site to test a little?

If not, we need to figure out why the module is not processing this page. 

I need to know that the multilanguageStatusCheck() methods is being called. If you have Tracy installed, could you replace that method with this:

    public function multilanguageStatusCheck(HookEvent $event) {

        $p = $event->object->getPage();

        // if actual noLang setting for this page's template is set to disabled (1) then exit now so we don't potentially enable
        if($p->template->noLang === 1) return;
        $parentsToMatch = array();
        foreach($this->data['multilanguageStatus'] as $pid => $settings) {
            if($settings['onlyThisPage'] != 1 || $p->id === $pid) $parentsToMatch[] = $pid;
        $pageMatchSelector = "id=".implode("|", $parentsToMatch);
        // parent() doesn't include current page
        $this->closestSpecifiedParent = $p->parent($pageMatchSelector);
        // closest() includes current page
        $this->closestMatch = $p->closest($pageMatchSelector);

        // if there's a match, set the noLang value for the page's template appropriately
        if(isset($this->data['multilanguageStatus'][$this->closestMatch->id])) {
            $p->template->noLang = ($this->data['multilanguageStatus'][$this->closestMatch->id]['status'] == 'disabled') ? '1' : '0';
        // if no match, then use default from config settings
        else {
            bd('no match');
            $p->template->noLang = $this->data['multilanguageDefaultStatus'] == 'disabled' ? '1' : '0';


and then post a screenshot of the dumps panel for me.

Link to comment
Share on other sites

I installed tracy module. But I could not know how to operate it.

Anyway, I could let you access the website as it is just a dummy default installation profile (nothing else). It is just for testing new modules for my own.




id: admin
pass: 123456

  • Like 1
Link to comment
Share on other sites

Glad to hear it's working with 2.8.

Sorry about the issue with 2.7 - I think perhaps the "noLang" template setting must have been introduced in 2.8/3.x

I'll update the modules directory to reflect this.

Thanks for the help debugging!

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

I just installed this module and with PW 3.0.95, Tracy shows me the following notices

PHP Notice: Trying to get property of non-object in ...\RestrictMultiLanguageBranch.module:140

line 140 code:

if($p->id === 1 || !isset($this->data['multilanguageStatus'][$this->closestSpecifiedParent->id])) {


  • 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

  • Create New...