gpt4 book ai didi

php - Magento Admin::删除特定角色/用户的菜单项

转载 作者:可可西里 更新时间:2023-11-01 13:00:27 24 4
gpt4 key购买 nike

我想从特定用户角色的管理菜单中删除一个菜单项。我见过其他人通过创建虚拟覆盖来做到这一点,但这些不是基于角色。我想在不使用其中一个 .xml 文件的情况下执行此操作。例如,有没有办法做到这一点; __construct() 还是 prepareLayout?

编辑:我必须补充一点,我想禁用的部分是 CMS 中的管理层次结构项。我知道我可以只为用户角色禁用层次结构,但我需要它来保存 CMS 页面。

最佳答案

我用自己的 block 扩展了 Mage_Adminhtml_Block_Page_Menu。我复制了函数“_buildMenuArray()”就在我返回菜单数组之前,我检查用户中的当前登录者是否不是管理员。如果是这样;我从菜单中删除了 Hierarchy 项,并将 Page 项的值设置为 last,以便正确显示阴影。

class Xxxxx_Xxxx_Block_Adminhtml_Page_Menu extends Mage_Adminhtml_Block_Page_Menu
{
protected function _buildMenuArray(Varien_Simplexml_Element $parent=null, $path='', $level=0)
{
if (is_null($parent)) {
$parent = Mage::getSingleton('admin/config')->getAdminhtmlConfig()->getNode('menu');
}

$parentArr = array();
$sortOrder = 0;
foreach ($parent->children() as $childName => $child) {
if (1 == $child->disabled) {
continue;
}

$aclResource = 'admin/' . ($child->resource ? (string)$child->resource : $path . $childName);
if (!$this->_checkAcl($aclResource)) {
continue;
}

if ($child->depends && !$this->_checkDepends($child->depends)) {
continue;
}

$menuArr = array();

$menuArr['label'] = $this->_getHelperValue($child);

$menuArr['sort_order'] = $child->sort_order ? (int)$child->sort_order : $sortOrder;

if ($child->action) {
$menuArr['url'] = $this->_url->getUrl((string)$child->action, array('_cache_secret_key' => true));
} else {
$menuArr['url'] = '#';
$menuArr['click'] = 'return false';
}

$menuArr['active'] = ($this->getActive()==$path.$childName)
|| (strpos($this->getActive(), $path.$childName.'/')===0);

$menuArr['level'] = $level;

if ($child->children) {
$menuArr['children'] = $this->_buildMenuArray($child->children, $path.$childName.'/', $level+1);
}
$parentArr[$childName] = $menuArr;

$sortOrder++;
}

uasort($parentArr, array($this, '_sortMenu'));

while (list($key, $value) = each($parentArr)) {
$last = $key;
}
if (isset($last)) {
$parentArr[$last]['last'] = true;
}

$data = $this->_isAdmin($parentArr);

return $data;
}

protected function _isAdmin($data){
$userRole = Mage::getSingleton('admin/session')->getUser()->getRole();
$roleName = $userRole->getRoleName();
$roleId = $userRole->getRoleId();
if ($roleName == 'Administrators' || $roleId == 1) {
return $data;
} else {
if (isset($data['hierarchy'])){
unset($data['hierarchy']);
$data['page']['last'] = 1;
}
if (isset($data['enterprise_page']['children']['hierarchy'])){
unset($data['enterprise_page']['children']['hierarchy']);
$data['enterprise_page']['children']['last'] = 1;
}
return $data;
}
}
}

关于php - Magento Admin::删除特定角色/用户的菜单项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7712237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com