mirror of
https://github.com/processwire/processwire.git
synced 2025-08-17 12:10:45 +02:00
Fix issue processwire/processwire-issues#60 where multi-language fields weren't working correctly with multi-instance
This commit is contained in:
@@ -503,6 +503,22 @@ class Modules extends WireArray {
|
||||
// attempt 2.x module in dedicated namespace or root namespace
|
||||
$className = $this->getModuleNamespace($moduleName) . $moduleName;
|
||||
}
|
||||
|
||||
if(ProcessWire::getNumInstances() > 1) {
|
||||
// in a multi-instance environment, ensures that anything happening during
|
||||
// the module __construct is using the right instance. necessary because the
|
||||
// construct method runs before the wire instance is set to the module
|
||||
$wire1 = ProcessWire::getCurrentInstance();
|
||||
$wire2 = $this->wire();
|
||||
if($wire1 !== $wire2) {
|
||||
ProcessWire::setCurrentInstance($wire2);
|
||||
} else {
|
||||
$wire1 = null;
|
||||
}
|
||||
} else {
|
||||
$wire1 = null;
|
||||
$wire2 = null;
|
||||
}
|
||||
|
||||
try {
|
||||
$module = $this->wire(new $className());
|
||||
@@ -511,6 +527,7 @@ class Modules extends WireArray {
|
||||
$module = null;
|
||||
}
|
||||
if($this->debug) $this->debugTimerStop($debugKey);
|
||||
if($wire1) ProcessWire::setCurrentInstance($wire1);
|
||||
return $module;
|
||||
}
|
||||
|
||||
|
@@ -560,6 +560,16 @@ class ProcessWire extends Wire {
|
||||
return self::$instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return number of instances
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
*/
|
||||
public static function getNumInstances() {
|
||||
return count(self::$instances);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a ProcessWire instance by ID
|
||||
*
|
||||
|
@@ -765,8 +765,20 @@ class WireFileTools extends Wire {
|
||||
*
|
||||
*/
|
||||
public function compile($file, array $options = array()) {
|
||||
static $compiled = array();
|
||||
if(strpos($file, '/modules/')) {
|
||||
// for multi-instance support, use the same compiled version
|
||||
// otherwise, require_once() statements in a file may not work as intended
|
||||
// applied just to site/modules for the moment, but may need to do site/templates too
|
||||
$f = str_replace($this->wire('config')->paths->root, '', $file);
|
||||
if(isset($compiled[$f])) return $compiled[$f];
|
||||
} else {
|
||||
$f = '';
|
||||
}
|
||||
$compiler = new FileCompiler(dirname($file), $options);
|
||||
return $compiler->compile(basename($file));
|
||||
$compiledFile = $compiler->compile(basename($file));
|
||||
if($f) $compiled[$f] = $compiledFile;
|
||||
return $compiledFile;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user