dreerr Posted June 3, 2017 Share Posted June 3, 2017 Dear forumreaders, I'm currently developing a big site for a museum. All pages of the site are available in DE and EN but there are general infos available in FR, IT, CZ, CN & JP. As these less important languages only populate one page, where as the two main languages populate approximately hundreds of pages it is probably not a good idea to setup all the languages in the backend, because most of the fields would be empty most of the time. Does anyone have an idea how to solve this? All the best, dreerr Link to comment Share on other sites More sharing options...
Zeka Posted June 3, 2017 Share Posted June 3, 2017 Hi @dreerr There is a module that lets you control whether multi-language support is enabled at the page / branch level, but it I don't think that it is exactly what you are looking for, because it disables all language for restricted pages / branches. But it can be a starting point. Maybe @adrian could say is it possible to tweak his module that you can select which languages are allowed for a specific page. 1 Link to comment Share on other sites More sharing options...
kixe Posted June 4, 2017 Share Posted June 4, 2017 (edited) How to disable/ enable specified languages in language fields for specified pages. 1.) Put this in your config.php and define pages and related languages via IDs /** * enable specified languages for specified pages in the page edit interface * use keys (IDs) for the pages and arrays of language->ids which you want to enable for this page * */ $config->editablePageLanguages = array( 1 => array(1072), // only one other language beside default 1634 => array() // only default ); 2.) Add this hook to your ready.php $this->addHookBefore('ProcessPageEdit::execute', function($e) { // get id of page beeing edited $pid = (int) $this->input->get('id'); if (!$pid) return; $configPageLanguages = $this->wire('config')->editablePageLanguages; if (!array_key_exists($pid, $configPageLanguages)) return; foreach ($this->wire('languages') as $lang) { if ($lang->isDefault() || in_array($lang->id, $configPageLanguages[$pid])) continue; $lang = $this->wire('languages')->get($lang->id); $lang->status = 1024; } $this->wire('languages')->reloadLanguages(); }); With a few changes within the foreach loop, you can change from whitelisting to blacklisting if this is more appropriate to your needs. Edited June 5, 2017 by kixe corrected inconsistence of var names (thanks @dreerr) 4 Link to comment Share on other sites More sharing options...
dreerr Posted June 5, 2017 Author Share Posted June 5, 2017 Dear @kixe thanks a lot for this approach! Sorry to correct you, but in your code the config variable differs, it should be $config->editablePageLanguages in config.php I wrote a small module for this, please feel free to use it! LanguagesHideInput.module.php <?php namespace ProcessWire; class LanguagesHideInput extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Hide Languages Input', 'version' => 1, 'singular' => true, 'autoload' => 'template=admin', 'requires' => 'ProcessWire>=3.0.0', ); } public function init() { $this->addHookBefore('ProcessPageEdit::execute', function($event) { $this->message=$this->allLanguagesPages; $page = $event->object->getPage(); if (!$page->id || $page->id==1 || $page->template->flags == Template::flagSystem) return; if (array_key_exists($page->id, $this->allLanguagesPages)) return; foreach ($this->wire('languages') as $lang) { if ($lang->isDefault() || in_array($lang->id, $this->defaultLanguages)) continue; $lang = $this->wire('languages')->get($lang->id); $lang->status = Page::statusHidden; } $this->wire('languages')->reloadLanguages(); }); } } LanguagesHideInput.config.php <?php namespace ProcessWire; class LanguagesHideInputConfig extends ModuleConfig { public function __construct() { $langs = []; foreach (wire('languages') as $language) { if ($language->name == "default") continue; $langs[$language->id] = ($language->title); } $this->add(array( 'defaultLanguages' => array( 'label' => __('Default Languages'), 'type' => 'Checkboxes', 'options' => $langs, 'value' => [], 'description' => __('Select the languages you want to show, others are hidden.'), ), 'allLanguagesPages' => array( 'type' => 'PageListSelectMultiple', 'label' => __('Exclusions'), 'description' => __('On these pages all the langauges will appear.'), ), )); } } 3 Link to comment Share on other sites More sharing options...
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