Commit bce3afcc by Luciano Baraglia

Module::getModule and Module::hasModule support for sub-modules - see #983

parent e574f10c
...@@ -333,7 +333,20 @@ abstract class Module extends Component ...@@ -333,7 +333,20 @@ abstract class Module extends Component
*/ */
public function hasModule($id) public function hasModule($id)
{ {
if (strpos($id, '/') === false) {
return isset($this->_modules[$id]); return isset($this->_modules[$id]);
} else {
// it's a sub-module
$ids = explode('/', $id);
$module = $this;
foreach ($ids as $id) {
if (!isset($module->_modules[$id])) {
return false;
}
$module = $module->getModule($id);
}
return true;
}
} }
/** /**
...@@ -345,6 +358,7 @@ abstract class Module extends Component ...@@ -345,6 +358,7 @@ abstract class Module extends Component
*/ */
public function getModule($id, $load = true) public function getModule($id, $load = true)
{ {
if (strpos($id, '/') === false) {
if (isset($this->_modules[$id])) { if (isset($this->_modules[$id])) {
if ($this->_modules[$id] instanceof Module) { if ($this->_modules[$id] instanceof Module) {
return $this->_modules[$id]; return $this->_modules[$id];
...@@ -353,6 +367,15 @@ abstract class Module extends Component ...@@ -353,6 +367,15 @@ abstract class Module extends Component
return $this->_modules[$id] = Yii::createObject($this->_modules[$id], $id, $this); return $this->_modules[$id] = Yii::createObject($this->_modules[$id], $id, $this);
} }
} }
} else {
// it's a sub-module
$ids = explode('/', $id);
$module = $this;
foreach ($ids as $id) {
$module = $module->getModule($id);
}
return $module;
}
return null; return null;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment