Skip to content

Commit

Permalink
using html helper for markup and fixing a bug where a module would lo…
Browse files Browse the repository at this point in the history
…ad moore than once based on routes
  • Loading branch information
dogmatic69 committed Nov 21, 2012
1 parent bf856c6 commit 86cd102
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions Core/Modules/View/Helper/ModuleLoaderHelper.php
Expand Up @@ -55,20 +55,17 @@ public function load($position = null, $admin = false) {
*/

$currentRoute = Configure::read('CORE.current_route');

$out = '<div class="modules '.$position.'">';
$out = array();
foreach($modules as $module) {
if (
($module['Theme']['name'] != '' && $module['Theme']['name'] != $this->theme) ||
in_array($module['Module']['module'], $this->moduleIgnoreOverload)
) {
//skip modules that are not for the current theme
$shouldSkip = ($module['Theme']['name'] != '' && $module['Theme']['name'] != $this->theme) ||
in_array($module['Module']['module'], $this->moduleIgnoreOverload);
if ($shouldSkip) {
continue;
}
$params = $this->__getModuleParams($module, $admin);

$params = $this->__getModuleParams($module, $admin);
if($params === false) {
continue; // from userland and its not active
continue;
}

$moduleOut = $this->loadModule($module['Module']['module'], $params);
Expand All @@ -78,18 +75,21 @@ public function load($position = null, $admin = false) {
if (!empty($module['ModuleRoute']) && $currentRoute instanceof CakeRoute) {
foreach($module['ModuleRoute'] as $route) {
if (empty($route['Route']['url']) || $route['Route']['url'] == $currentRoute->template) {
$out .= $moduleOut;
$out[] = $moduleOut;
break;
}
}
}

else if (empty($module['ModuleRoute']) || $error) {
$out .= $moduleOut;
} else if (empty($module['ModuleRoute']) || $error) {
$out[] = $moduleOut;
}
}
$out .= '</div>';

return $out;
return $this->Html->tag('div', implode('', $out), array(
'class' => array(
'modules',
$position
)
));
}

/**
Expand Down Expand Up @@ -134,8 +134,17 @@ public function loadModule($module = null, $params = array()) {
$moduleOut = $e->getMessage();
}
}
if(!$moduleOut) {
return false;
}

return sprintf('<div class="module %s %s">%s</div>', str_replace('/', '-', $module), $class, $moduleOut);
return $this->Html->tag('div', $moduleOut, array(
'class' => array(
'module',
str_replace('/', '-', $module),
$class
)
));
}

/**
Expand Down Expand Up @@ -182,20 +191,12 @@ public function loadDirect($module, $params = array()) {
}
}

$module = sprintf('%s.%s', $plugin, $module);
$module = implode('.', array($plugin, $module));

try{
return $this->_View->element($module, array('config' => $params));
}

catch(Exception $e) {
$message = sprintf(
'Error: Could not load module "%s" (%s)',
$module,
$e->getMessage()
);

throw new Exception($message);
} catch(Exception $e) {
throw new CakeException(__d('modules', 'Error: Could not load module "%s" (%s)', $module, $e->getMessage()));
}
}

Expand Down

0 comments on commit 86cd102

Please sign in to comment.