Skip to content

Commit

Permalink
use capabilities array to set 'default' admin link where possible. refs
Browse files Browse the repository at this point in the history
  • Loading branch information
craigh committed Jul 24, 2015
1 parent a44c91a commit ce7289d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
11 changes: 5 additions & 6 deletions src/lib/legacy/viewplugins/function.adminpanelmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function smarty_function_adminpanelmenu($params, Zikula_View $view)
// add override for panel width created from .scss file
PageUtil::addVar('stylesheet', '@ZikulaAdminModule/Resources/public/css/mmenu-hiddenpanel-customwidth.css');

$router = $view->getContainer()->get('router');
$modules = ModUtil::getModulesCapableOf('admin');
// sort modules by displayname
$moduleNames = array();
Expand All @@ -60,19 +61,17 @@ function smarty_function_adminpanelmenu($params, Zikula_View $view)
if (SecurityUtil::checkPermission("module[name]::", '::', ACCESS_EDIT)) {
// first-level list - list modules with general 'index' link
$img = ModUtil::getModuleImagePath($module['name']);
try {
$url = ModUtil::url($module['name'], 'admin', 'index');
} catch (\Exception $e) {
$url = '#';
}
$url = isset($module['capabilities']['admin']['url'])
? $module['capabilities']['admin']['url']
: $router->generate($module['capabilities']['admin']['route']);
$moduleSelected = empty($moduleSelected) && strpos($view->getRequest()->getUri(), $module['url']) ? " class='Selected'" : "";
$htmlContent .= "<li{$moduleSelected}><a href=\"" . DataUtil::formatForDisplay($url) . "\"><img src=\"$img\" alt=\"\" style=\"height: 18px\" /> " . $module['displayname'] . "</a>";
try {
$links = (array)ModUtil::apiFunc($module['name'], 'admin', 'getLinks');
} catch (\Exception $e) {
$links = array();
}
if (count($links) > 0) {
if ((count($links) > 0) && ($links[0] != false)) {
// create second-level list from module adminLinks
$htmlContent .= '<ul class="text-left">';
foreach ($links as $link) {
Expand Down
25 changes: 14 additions & 11 deletions src/system/Zikula/Module/AdminModule/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public function adminpanelAction($acid = null)
$displayNameType = $this->getVar('displaynametype', 1);

// get admin capable modules
$adminmodules = ModUtil::getAdminMods();
$adminmodules = ModUtil::getModulesCapableOf('admin');
$adminlinks = array();
foreach ($adminmodules as $adminmodule) {
if (SecurityUtil::checkPermission("{$adminmodule['name']}::", 'ANY', ACCESS_EDIT)) {
Expand All @@ -371,26 +371,27 @@ public function adminpanelAction($acid = null)
$order = ModUtil::apiFunc('ZikulaAdminModule', 'admin', 'getSortOrder',
array('mid' => ModUtil::getIdFromName($adminmodule['name'])));
if (($catid == $acid) || (($catid == false) && ($acid == $this->getVar('defaultcategory')))) {
$modinfo = ModUtil::getInfoFromName($adminmodule['name']);
$menutexturl = ModUtil::url($modinfo['name'], 'admin', 'index');
$menutexturl = isset($adminmodule['capabilities']['admin']['url'])
? $adminmodule['capabilities']['admin']['url']
: $this->get('router')->generate($adminmodule['capabilities']['admin']['route']);

if ($displayNameType == 1) {
$menutext = $modinfo['displayname'];
$menutext = $adminmodule['displayname'];
} elseif ($displayNameType == 2) {
$menutext = $modinfo['name'];
$menutext = $adminmodule['name'];
} elseif ($displayNameType == 3) {
$menutext = $modinfo['displayname'] . ' (' . $modinfo['name'] . ')';
$menutext = $adminmodule['displayname'] . ' (' . $adminmodule['name'] . ')';
}
$menutexttitle = $modinfo['description'];
$menutexttitle = $adminmodule['description'];

$adminicon = ModUtil::getModuleImagePath($adminmodule['name']);

$adminlinks[] = array('menutexturl' => $menutexturl,
'menutext' => $menutext,
'menutexttitle' => $menutexttitle,
'modname' => $modinfo['name'],
'modname' => $adminmodule['name'],
'adminicon' => $adminicon,
'id' => $modinfo['id'],
'id' => $adminmodule['id'],
'order'=> $order);
}
}
Expand Down Expand Up @@ -557,15 +558,17 @@ public function categorymenuAction($acid = null)
}

// get admin capable modules
$adminmodules = ModUtil::getAdminMods();
$adminmodules = ModUtil::getModulesCapableOf('admin');
$adminlinks = array();

foreach ($adminmodules as $adminmodule) {
if (SecurityUtil::checkPermission("$adminmodule[name]::", '::', ACCESS_EDIT)) {
$catid = ModUtil::apiFunc('ZikulaAdminModule', 'admin', 'getmodcategory', array('mid' => $adminmodule['id']));
$order = ModUtil::apiFunc('ZikulaAdminModule', 'admin', 'getSortOrder',
array('mid' => ModUtil::getIdFromName($adminmodule['name'])));
$menutexturl = ModUtil::url($adminmodule['name'], 'admin', 'index');
$menutexturl = isset($adminmodule['capabilities']['admin']['url'])
? $adminmodule['capabilities']['admin']['url']
: $this->get('router')->generate($adminmodule['capabilities']['admin']['route']);
$menutext = $adminmodule['displayname'];
$menutexttitle = $adminmodule['description'];
$adminlinks[$catid][] = array('menutexturl' => $menutexturl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public function changeModuleCategoryAction()

//get the module name
$displayname = DataUtil::formatForDisplay($module['displayname']);
$url = isset($module['capabilities']['admin']['url'])
? $module['capabilities']['admin']['url']
: $this->get('router')->generate($module['capabilities']['admin']['route']);
$module = $module['name'];
$oldcid = ModUtil::apiFunc('ZikulaAdminModule', 'admin', 'getmodcategory', array('mid' => $moduleID));

Expand All @@ -71,7 +74,7 @@ public function changeModuleCategoryAction()
$output = array(
'id' => $moduleID,
'name' => $displayname,
'url' => ModUtil::url($module, 'admin', 'index'),
'url' => $url,
'parentCategory' => $newParentCat,
'oldCategory' => $oldcid,
);
Expand Down
20 changes: 10 additions & 10 deletions src/system/Zikula/Module/BlocksModule/Api/MenutreeApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function adminlinks($args)
}

// Now work on admin capable modules
$adminmodules = ModUtil::getAdminMods();
$adminmodules = ModUtil::getModulesCapableOf('admin');
$displayNameType = ModUtil::getVar('ZikulaAdminModule', 'displaynametype', 1);
$default_cid = ModUtil::getVar('ZikulaAdminModule', 'startcategory');
$adminlinks = array();
Expand All @@ -143,28 +143,28 @@ public function adminlinks($args)
array('mid' => ModUtil::getIdFromName($adminmodule['name'])));
$cid = (isset($catinfo[$cid])) ? $cid : $default_cid; // make sure each module is assigned a category

$modinfo = ModUtil::getInfo(ModUtil::getIdFromName($adminmodule['name']));

if ($modinfo['type'] == 2 || $modinfo['type'] == 3) {
$menutexturl = ModUtil::url($modinfo['name'], 'admin', 'index');
if ($adminmodule['type'] == 2 || $adminmodule['type'] == 3) {
$menutexturl = isset($adminmodule['capabilities']['admin']['url'])
? $adminmodule['capabilities']['admin']['url']
: $this->get('router')->generate($adminmodule['capabilities']['admin']['route']);
} else {
$menutexturl = 'admin.php?module=' . $modinfo['name'];
$menutexturl = 'admin.php?module=' . $adminmodule['name'];
}

if ($displayNameType == 1) {
$menutext = $modinfo['displayname'];
$menutext = $adminmodule['displayname'];
} elseif ($displayNameType == 2) {
$menutext = $modinfo['name'];
$menutext = $adminmodule['name'];
} elseif ($displayNameType == 3) {
$menutext = $modinfo['displayname'] . ' (' . $modinfo['name'] . ')';
$menutext = $adminmodule['displayname'] . ' (' . $adminmodule['name'] . ')';
}

$adminlinks[] = array(
$lang => array(
'id' => $idoffset++,
'name' => $menutext,
'href' => $menutexturl,
'title' => $modinfo['description'],
'title' => $adminmodule['description'],
'className' => '',
'state' => 1,
'lang' => $lang,
Expand Down

0 comments on commit ce7289d

Please sign in to comment.