创建 Drupal 安装配置文件
由 lugir 于 星期六, 06/25/2011 - 15:30 发布
Drupal 的安装配置文件位于 Drupal 安装目录下的 profiles 目录中,以 example.profiles 的形式进行命名,一个典型的安装配置文件包含以下函数:
注意:本文使用 example 做为示例用的安装配置文件名称,在创建你自己的安装配置文件时,请更改为你的安装配置文件名称,如 drupal_corporate,等等。
1. example_profile_modules() - 必备
<?php
/**
* Return an array of the modules to be enabled when this profile is installed.
*
* @return
* An array of modules to be enabled.
*/
function profilename_profile_modules() {
return array(
// Enable required core modules first.
'block', 'filter', 'node', 'system', 'user', 'watchdog',
// Enable optional core modules next.
'blog', 'color', 'comment', 'forum', 'help', 'menu', 'taxonomy',
// Then, enable any contributed modules here.
'og', 'views', 'views_ui', 'views_rss',
);
}
?>
此函数定义了使用安装配置文件时,Drupal 要启用的模块以及模块的启用顺序。定义在此函数中的模块,如果存在,将会依次被调用 .install 文件进行启用。注意必须在安装配置文件中启用 'system', 'block' 等系统模块,为了保证模块启用的正确性,复制 profiles/default/default.profile 做为编写 profile 的范本,是推荐的方法。
注意事项:http://drupal.org/node/67921
2. myprofile_profile_detail() - 必备
<?php
/**
* Return a description of the profile for the initial installation screen.
*
* @return
* An array with keys 'name' and 'description' describing this profile.
*/
function example_profile_details() {
return array(
'name' => 'Example profile',
'description' => 'This example profile will install some commonly used contrib modules.',
);
}
?>
3. example_profile_task_list() -(可选)
<?php
function example_profile_task_list() {
return array(
// Here we define names of the custom tasks we're about to perform,
// so that these will be shown in the tasks list on the
// installer UI. The keys may be anything (internal use only),
// excepting the reserved tasks (as listed in install_reserved_tasks()
// inside install.php). The strings may be translated with the st()
// wrapper (translations provided in the install profile's .po file),
// but sometimes there's no point in doing that, if the profile is
// only focused to a single language. We only need to list tasks,
// for which a page will be displayed; internally, unlisted keys
// may be well used too. It's also possible to return dynamic data
// here, adding/removing tasks on-the-fly depending on previous
// steps.
'task1' => st('Example question'),
'task2' => st('Example summary'),
);
}
?>
4. default_profile_tasks()
<?php
function default_profile_tasks(&$task, $url) {
// Insert default user-defined node types into the database. For a complete
// list of available node type attributes, refer to the node type API
// documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info.
$types = array(
array(
'type' => 'page',
'name' => st('Page'),
'module' => 'node',
'description' => st("A <em>page</em>, similar in form to a <em>story</em>, is a simple method for creating and displaying information that rarely changes, such as an \"About us\" section of a website. By default, a <em>page</em> entry does not allow visitor comments and is not featured on the site's initial home page."),
'custom' => TRUE,
'modified' => TRUE,
'locked' => FALSE,
'help' => '',
'min_word_count' => '',
),
array(
'type' => 'story',
'name' => st('Story'),
'module' => 'node',
'description' => st("A <em>story</em>, similar in form to a <em>page</em>, is ideal for creating and displaying content that informs or engages website visitors. Press releases, site announcements, and informal blog-like entries may all be created with a <em>story</em> entry. By default, a <em>story</em> entry is automatically featured on the site's initial home page, and provides the ability to post comments."),
'custom' => TRUE,
'modified' => TRUE,
'locked' => FALSE,
'help' => '',
'min_word_count' => '',
),
);
foreach ($types as $type) {
$type = (object) _node_type_set_defaults($type);
node_type_save($type);
}
// Default page to not be promoted and have comments disabled.
variable_set('node_options_page', array('status'));
variable_set('comment_page', COMMENT_NODE_DISABLED);
// Don't display date and author information for page nodes by default.
$theme_settings = variable_get('theme_settings', array());
$theme_settings['toggle_node_info_page'] = FALSE;
variable_set('theme_settings', $theme_settings);
// Update the menu router information.
menu_rebuild();
}
?>
在 default_profile_tasks() 函数中,可以执行 example_profile_modules() 安装完模块之后的一些操作。在此函数中,可以使用整个 Drupal API 提供的功能来实现所需要的操作,如定义任意自定义内容类型、创建术语表及词汇、更改变量设置值等等。
在安装配置文件中 default_profile_tasks() 函数中取得模块配置及自定义内容的方法
- 进行更新改使用 phpMyAdmin 或 mysqldump 导出数据库
- 更改 Drupal 某些表单中设置的值
- 再导出一份数据库
- 对先后两个数据库执行 diff 对比操作
- 找出两份数据库中不同的行,将不同的内容通过 default_profile_tasks() 函数在安装过程中实现