bit3 / contao-nested-menu
1.1.3
2013-12-21 20:51 UTC
Requires
- php: >=5.3
- bit3/contao-twig: ~1.3
- contao-community-alliance/composer-installer: *
- contao/core: >=2.11,<4
Requires (Dev)
Replaces
- contao-legacy/nested-menu: 1.1.3
README
嵌套菜单的好处是减少后端菜单项的数量,并将它们分组到子菜单中。
定义嵌套菜单项
首先你需要一个包含大量条目的导航设置。
$GLOBALS['BE_MOD']['my'] = array( 'entry1' => array( 'tables' => array('table1'), ), 'entry2' => array( 'tables' => array('table2'), ), 'entry3' => array( 'tables' => array('table3'), ), 'entry4' => array( 'tables' => array('table4'), ), 'entry5' => array( 'tables' => array('table5'), ), 'entry6' => array( 'tables' => array('table6'), ), 'entry7' => array( 'tables' => array('table7'), ), 'entry8' => array( 'tables' => array('table8'), ), 'entry9' => array( 'tables' => array('table9'), ), );
现在你需要定义哪个条目将被嵌套到另一个条目中。
$GLOBALS['BE_MOD']['my'] = array( 'entry1' => array( 'tables' => array('table1'), ), 'entry2' => array( 'tables' => array('table2'), ), 'entry3' => array( 'tables' => array('table3'), ), 'entry4' => array( 'tables' => array('table4'), ), 'entry5' => array( 'nested' => 'grouped_entries', 'tables' => array('table5'), ), 'entry6' => array( 'nested' => 'grouped_entries', 'tables' => array('table6'), ), 'entry7' => array( 'nested' => 'grouped_entries', 'tables' => array('table7'), ), 'entry8' => array( 'nested' => 'grouped_entries', 'tables' => array('table8'), ), 'entry9' => array( 'nested' => 'grouped_entries', 'tables' => array('table9'), ), );
现在将创建一个类似这样的 虚拟 结构
$GLOBALS['BE_MOD']['my'] = array( 'entry1' => array( 'tables' => array('table1'), ), 'entry2' => array( 'tables' => array('table2'), ), 'entry3' => array( 'tables' => array('table3'), ), 'entry4' => array( 'tables' => array('table4'), ), 'grouped_entries' => array( 'callback' => 'NestedMenuController', ), );
请注意,条目 entry5
到 entry9
只对用户隐藏。
新条目 grouped_entries
现在提供了一个与 Contao 2 后端首页中已知的老式导航列表类似的导航列表。
也可以在子菜单中创建不同的组,只需在 nested
键中添加 :group-name
。
$GLOBALS['BE_MOD']['my'] = array( 'entry1' => array( 'tables' => array('table1'), ), 'entry2' => array( 'tables' => array('table2'), ), 'entry3' => array( 'tables' => array('table3'), ), 'entry4' => array( 'tables' => array('table4'), ), 'entry5' => array( 'nested' => 'grouped_entries:group1', 'tables' => array('table5'), ), 'entry6' => array( 'nested' => 'grouped_entries:group1', 'tables' => array('table6'), ), 'entry7' => array( 'nested' => 'grouped_entries:group2', 'tables' => array('table7'), ), 'entry8' => array( 'nested' => 'grouped_entries:group2', 'tables' => array('table8'), ), 'entry9' => array( 'nested' => 'grouped_entries:group3', 'tables' => array('table9'), ), );
现在 entry5
和 entry6
将被分组,entry7
和 entry8
将被分组,并且 entry9
也将有自己的组。
翻译
每个子菜单组都需要在 $GLOBALS['TL_LANG']['MOD']
数组中有一个语言键,等于组名。
$GLOBALS['TL_LANG']['MOD']['grouped_entries:group1'] = 'Group 1'; $GLOBALS['TL_LANG']['MOD']['grouped_entries:group2'] = 'Group 2'; $GLOBALS['TL_LANG']['MOD']['grouped_entries:group3'] = 'Group 3';
安全性
因为嵌套菜单只是视觉上的修改,你可以为每个单独的菜单项,包括分组的条目本身,授予或限制访问权限。你不会错过 Contao 提供的所有权限。