Permalink
Browse files

Fix issue #1771 where module duplicates selection wasn't working. Als…

…o add support for multi-language module configuration fields per request from @CanRau
  • Loading branch information...
ryancramerdesign committed Apr 12, 2016
1 parent 48d0a29 commit 2fe134b7b059fff023f0f37c7f172a9853c88af2
Showing with 41 additions and 8 deletions.
  1. +4 −5 wire/core/Modules.php
  2. +37 −3 wire/modules/Process/ProcessModule/ProcessModule.module
View
@@ -735,7 +735,6 @@ protected function loadModulesTable() {
protected function load($path) {
$debugKey = $this->debug ? $this->debugTimerStart("load($path)") : null;
$installed =& $this->modulesTableCache;
$modulesLoaded = array();
$modulesDelayed = array();
@@ -748,14 +747,15 @@ protected function load($path) {
$pathname = trim($pathname);
if(empty($pathname)) continue;
$basename = basename($pathname);
list($moduleName, $ext) = explode('.', $basename, 2);
list($moduleName, $ext) = explode('.', $basename, 2); // i.e. "module.php" or "module"
$this->moduleFileExts[$moduleName] = $ext === 'module' ? 1 : 2;
$this->setConfigPaths($moduleName, dirname($basePath . $pathname));
// @todo next, remove the 'file' property from verbose module info since it is redundant
$requires = array();
$name = $moduleName;
$moduleName = $this->loadModule($path, $pathname, $requires, $installed);
if(!$this->wire('config')->paths->get($name)) $this->setConfigPaths($name, dirname($basePath . $pathname));
if(!$moduleName) continue;
if(count($requires)) {
@@ -874,8 +874,7 @@ protected function loadModule($basepath, $pathname, array &$requires, array &$in
}
$info = $installed[$basename];
// $this->setConfigPaths($basename, $dirname);
$this->setConfigPaths($basename, $dirname);
$module = null;
$autoload = false;
@@ -13,6 +13,8 @@
*
* ProcessWire 3.x (development), Copyright 2015 by Ryan Cramer
* https://processwire.com
*
* @todo add support for module configuration inputfields with useLanguages option
*
*/
@@ -1104,6 +1106,7 @@ class ProcessModule extends Process {
$out = '';
$moduleId = $this->modules->getModuleID($moduleName);
$languages = $this->wire('languages');
$collapseInfo = $this->wire('input')->get('collapse_info') || $this->wire('input')->get('modal') ? '&collapse_info=1': '';
if(!$moduleId) {
$this->error("Unknown module");
@@ -1153,6 +1156,7 @@ class ProcessModule extends Process {
$field = $this->modules->get('InputfieldRadios');
$field->attr('name', '_use_duplicate');
$field->label = $this->_('Module file to use');
$field->icon = 'files-o';
$field->description = $this->_('There are multiple copies of this module. Select the module file you want to use.');
foreach($duplicates['files'] as $file) {
$field->addOption($file);
@@ -1162,8 +1166,10 @@ class ProcessModule extends Process {
}
$fields = $this->wire('modules')->getModuleConfigInputfields($moduleName);
if($fields) foreach($fields as $field) {
$form->add($field);
if($fields) {
foreach($fields as $field) {
$form->add($field);
}
}
// uninstall checkbox
@@ -1205,12 +1211,28 @@ class ProcessModule extends Process {
} else {
$this->message($this->_("This module doesn't have any fields to configure"));
}
$data = null;
if($languages && $fields) {
// multi-language support for Inputfield with useLanguages==true
// we populate the language values from module config data so module doesn't have to do this
$data = $this->modules->getModuleConfigData($moduleName);
foreach($fields->getAll() as $field) {
if(!$field->useLanguages) continue;
foreach($languages as $language) {
if($language->isDefault()) continue;
$name = $field->name . '__' . $language->id;
if(!isset($data[$name])) continue;
$field->set("value$language->id", $data[$name]);
}
}
}
// check for submitted form
$submitSave = $this->input->post('submit_save_module');
if($submitSave) {
$data = $this->modules->getModuleConfigData($moduleName);
if(is_null($data)) $data = $this->modules->getModuleConfigData($moduleName);
$form->processInput($this->input->post);
$updatedNames = array();
@@ -1220,6 +1242,18 @@ class ProcessModule extends Process {
$value = $field->attr('value');
if(!isset($data[$name]) || $value != $data[$name]) $updatedNames[] = $name;
$data[$name] = $value;
// multi-language, if Inputfield specifies useLanguages==true
// convert value1234 inputfield values to module config data in name__1234 format
if($languages && $field->useLanguages) {
$_name = $name;
foreach($languages as $language) {
if($language->isDefault()) continue;
$name = $_name . "__" . $language->id;
$value = $field->get("value$language->id");
if(!isset($data[$name]) || $value != $data[$name]) $updatedNames[] = $name;
$data[$name] = $value;
}
}
}
}

1 comment on commit 2fe134b

@CanRau

This comment has been minimized.

Show comment
Hide comment
@CanRau

CanRau Apr 12, 2016

You're really amazing, thank you very much, module config language fields just work now 👯

CanRau commented on 2fe134b Apr 12, 2016

You're really amazing, thank you very much, module config language fields just work now 👯

Please sign in to comment.