You are here

Drupal专业开发指南 第23章 定义附加的安装任务

g089h515r806 的头像
Submitted by g089h515r806 on 星期五, 2009-09-04 11:23

注意图23-1中左边栏中的任务列表(“选择轮廓,”“选择语言,” “验证需求,”等等)。让我们通过在我们的安装轮廓中定义一些任务,来将它们也添加到这个列表中。我们将编写一个函数,它的名字为:我们的轮廓名字+_profile_task_list:

 
/**
 * Return a list of tasks that this profile supports.
 *
 * @return
 * A keyed array of tasks the profile will perform during
 * the final stage. The keys of the array will be used internally,
 * while the values will be displayed to the user in the installer
 * task list.
*/
function university_profile_task_list() {
    return array(
        'dept-info' => st('Departmental Info'),
        'support-message' => st('Support'),
    );
}
 
选择了我们的轮廓以后,我们将看到刚刚定义的任务,如图23-3所示。
23-3.轮廓定义的任务(部门信息和支持)显示在了左边栏
 
    安装器将执行一系列的任务,包括内置任务和你的安装轮廓可能定义的任务。表23-2给出了内置任务列表。自定义任务时,确保在你的任务数组中定义的键的唯一性,也就是与内置任务的任务标识不冲突。
 
23-2.任务的名字和描述,这里按照它们的执行顺序进行排列
任务标识符            描述
profile-select          选择轮廓*
locale-select           选择语言
requirements            验证系统需求
database                设立数据库
profile-install         为模块的安装和启用准备批处理
profile-install-batch  安装轮廓(安装和启用模块)
locale-initial-import  为用于导入的界面翻译准备批处理
locale-initial-batch    通过导入.po文件设立翻译
configure               配置站点(用户填写表单)
profile                 将控制权转交给安装轮廓的_profile_tasks()函数
profile-finished        为用于导入的剩余界面翻译准备批处理
locale-remaining-batch 设立剩余翻译
finished                告诉用户安装已完成
done                    重构表单,注册动作,和显示初始页面
*如果仅有默认轮廓可用,那么在用户界面将不会显示“选择轮廓”任务,而“安装轮廓”任务也被重命名为了“安装站点”。
 
    你定义的任务用来指示安装流程中的步骤;在这里定义任务的目的是,让Drupal将它们包含在用户界面中。如果你想让你的安装轮廓更加模块化,那么你完全可以在university_profile_task_list()中定义更多的任务,但是在定义任务时,一定要避免与已有任务的命名冲突。

Drupal版本: