第五节 定义你自己的管理页面

定义你自己的管理页面
 
Drupal有几种不同类别的管理设定,像内容管理,用户管理,都是展现在主管理页面上的。如果你的模块需要一个自己的分类,创建它是非常容易的事情。在这个例子中,我们通过修改模块的menu钩子来创建一个新的、名为“Node annotation”的分类,依然是用黑体部分代表添加或修改:
 
/**
* Implementation of hook_menu().
*/
function annotate_menu() {
$items['admin/annotate'] = array(
'title' => 'Node annotation',
'description' => 'Adjust node annotation options.',
'position' => 'right',
'weight' => -5,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
$items['admin/annotate/settings'] = array(
'title' => 'Annotation settings',
'description' => 'Change how annotations behave.',
'page callback' => 'drupal_get_form',
'page arguments' => array('annotate_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
'file' => 'annotate.admin.inc',
);
 
return $items;
}
 
随着代码的改变,我们模块的名字将作为一个新的分类链接出现在菜单上。(如图2-3
 
            2-3 导向annotation的设定页面的链接现在是一个新的独立的分类了
 
如果你是在本地进行操作,你需要清空菜单缓存才能看见以上链接。去掉数据库中的cache_menu表,或者点击development模块(devel.module)中的“Rebuild menus”选项,又或者使用Administer > Site configuration > Performance页面中的Clear cached data按钮都可以达到目的。
 
Tipdevelopment模块(http://drupal.org/project/devel)是专为支持Drupal开发而写的。它可以让你快捷的使用清空缓存,访问变量,追踪请求,以及其他大量的开发用函数,它简直是开发必备模块之一。如果你还没安装,那赶快去下载放在sites/all/modules/devel目录下吧,然后就是Administer > Site building > Blocks页面开启它了。
 
我们分两步建立了新的分类。第一步,我们添加了个菜单项(实际是一个特殊的路径admin/annotate)用来描述这个分类的标题。通过将它的权重设置为-5,我们将它放置在了一个正确的位置,正如图2-3中所见,就在“Site configuration”分类的上面。
 
第二步是让Drupal把指向annotation settings的链接放在“Node annotation”分类中。修改一下我们创建的路径就可以做到这点,所以路径就从admin/settings/annotate变成了admin/annotate/settings。以前,这个菜单项是admin/settings的一个子类,就像表2-1中所示,其路径是指向“Site configuration”分类的。当Drupal重建整个菜单树的时候,它会分析和确定各个菜单项之间的从属关系,此时由于admin/annotate/settings是admin/annotate的子类,所以在显示上也依据于这个关系。也就是说将模块的菜单项呈树状放在表2-1那种路径之下,就可以让它们在Drupal的管理页面显现出来了。
 
Drupal在应对请求的时候,只会读取必要的文件,这样可以节约内存的使用。因为我们的page callback指向的函数并不在我们的模块包含的范围之内(实际是syatem.module文件中的system_admin_menu_block_page()函数),所以我们需要让Drupal读取的文件就是modules/system/system.admin.inc,而不是sites/all/modules/custom/annotate/
system.admin.inc文件。为了做到此点,我们让Drupal获取了系统模块的路径,并将结果作为菜单项中file path一项的值。
 
当然,这个例子显得有些不自然,在实际应用中,你应该有更好的理由去创建一个新的分类,以免太多的分类困扰着你的管理员(通常这个管理员就是你自己!)。
 
       表2-1 指向对各个分类进行管理的路径
 
 
 

评论

Ed HardyThe blog is really informative and i like to share it with my friends we can easily learn more about web designing through this post thanks for post
Ed Hardy Shoes
Ed Hardy clothes
Cheap Ed HardyThe site was very informative however it didn't have the information I was looking for.
Ed Hardy Womens Jeans
Ed Hardy Womens Knits
Ed Hardy Womens Swimwear
Ed Hardy Womens T-Shirts
Ed Hardy BagsIt must've taken you a bit of time, so thanks for taking the time to do so, I appreciate it, This post is just great, I'll read the rest of your blog...
Ed Hardy Belts
Ed Hardy Caps
Abercrombie Fitch

There are lotsof ideas here!!!!!!!!! VCP-410 but people seem to be very casual with this site!!!!!!!!!!!!! 350-001 Any body interested in a joint venture ? 640-802 I got some stuff to share vmware certification i book mark it and mail all of my friends also.