Jump to content

Restrict Multi-Language Branch


adrian
 Share

Recommended Posts

  • 6 months later...
  • 4 weeks later...

@adrian Hi Adrian,

I quickly  tried your module and find it very useful. But does it work with repeater fields? I couldn't get it working ... I played a bit around and found another simple solution.


config.php

/**
 * array of pages or page trees having multilanguage disabled in the edit screen
 *
 */
$config->singleLanguagePages = array(11973 => 0, 12334 => 0);

ready.php

/**
 * disable multilanguage in Page Edit for specified pages or page trees
 * define array of single language pages in $config
 * where the key is the page id and the value defines if the page acts as a tree parent or only for a single page
 */
$wire->addHookBefore('ProcessPageEdit::execute', function($e) {
    $page = $e->object->getPage();
    $slps = $this->wire('config')->singleLanguagePages;
    // exit if doesn't match
    if (empty($slps)) return;
    $parentIDs = array_intersect($page->parents()->prepend($page)->each('id'), array_keys($slps));
    if (empty($parentIDs)) return;
    foreach ($parentIDs as $parentID) {
        if ($page->id == $parentID) break; // page matches itself
        if ($slps[$parentID]) break; // page is part of a single language tree
        return;
    }
    // page is set as a single language page
    $page->template->noLang = 1;
    // we want repeater fields single language as well
    foreach ($page->fields as $f) {
        if ($f->type instanceof FieldtypeRepeater == false) continue;
        $this->wire('templates')->get(FieldtypeRepeater::templateNamePrefix . $f->name)->noLang = 1;
    }
});

 

  • Like 2
Link to comment
Share on other sites

Thanks @kixe - I didn't have a need for repeaters when I wrote this module, but it's certainly a good idea to support them. I have gone ahead and updated the module based on your idea and it now works for repeaters as well.

Thanks!

  • Like 2
  • Thanks 2
Link to comment
Share on other sites

  • 2 years later...
On 11/26/2016 at 2:06 AM, adrian said:

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.

I have just found this module and once again am astonished at the scope of interest and productivity of @adrian! Whatever I am looking for years after I started using PW he already has a module for written when I was just messing around ? This one is the great example.

But the module is not as perfect as it could be. There is an issue (see above) that does not allow it to work as desired. I just added my thumbs up for the issue on github that makes the enhancement of the module (and custom hooks too) possible. Bumping this thread, so those of us working with multi-language sites could give their thumbs too to move the issue forward (it was waiting for us for a long time))

P.S. Multi-language support is one of the PW's selling points, so I feel proud making any step to improvement in this field)

  • Like 5
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...