Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Apress.Pro.Drupal.7.Development.3rd.Edition.Dec.2010.pdf
Скачиваний:
73
Добавлен:
14.03.2016
Размер:
12.64 Mб
Скачать

CHAPTER 24 INSTALLATION PROFILES

Using hook_install_tasks and hook_install_tasks_alter

There may be instances where you would like to see the list of tasks that will be performed during the installation process or modify the tasks defined in a profile. You can use hook_install to retrieve a keyed array of tasks the profile will perform during the final stage of the installation. Each key represents the name of a function (usually a function defined by this profile, although that is not strictly required) that is called when that task is run. For more information about hook_install, see http://api.drupal.org/api/function/hook_install_tasks/7.

If you want to alter the tasks that are performed at installation, you can use hook_install_tasks_alter. The function signature of this hook is hook_install_tasks_alter(&$tasks, $install_state), where

$tasks is an array of all available installation tasks, including those provided by Drupal core. You can modify this array to change or replace any part of the Drupal installation process that occurs after the installation profile is selected.

$install_state is an array of information about the current installation state.

The Demo Profile module (http://drupal.org/project/demo_profile) utilizes hook_install_tasks_alter to remove some of the installation tasks defined in an installation profile. The reason for this is the module installs a backup of an existing site (http://drupal.org/project/demo) as the starting point for a new site. Since the database backup includes many of the tables required to get the site up and running, we don’t want the installation process to wipe out those tables. As you can see from the following example code, the module removes tasks like installing core (install_system_module), users (install_profile_modules), locales (install_import_locales), etc.

function demo_profile_install_tasks_alter(&$tasks, &$install_state) {

// save the bootstrap and install finished tasks – we’ll use them again later in the process $install_bootstrap_full = (array) $tasks['install_bootstrap_full'];

$install_finished = (array) $tasks['install_finished'];

//Remove the tasks from the list and execution.

//We cannot implement hook_install_tasks(), because we want to intercept the

//installation process before it even begins (except database settings). unset(

$tasks['install_system_module'], $tasks['install_bootstrap_full'], $tasks['install_profile_modules'], $tasks['install_import_locales'], $tasks['install_configure_form'], $tasks['install_import_locales_remaining'], $tasks['install_finished']

);

543

CHAPTER 24 INSTALLATION PROFILES

//Add Demonstration site profile tasks.

//@todo Move dump path setting into separate step; store value in

//$install_state.

$tasks['demo_profile_form'] = array( 'display_name' => st('Choose snapshot'), 'type' => 'form',

'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED,

);

// Do a full bootstrap and display final message. $tasks['install_bootstrap_full'] = $install_bootstrap_full; $tasks['install_finished'] = $install_finished;

}

Summary

If you find yourself building the same types of sites over and over again, I would suggest taking a close look at using Drupal installation profiles as a means for jumpstarting the site creation process. Installation profiles automate many of the tasks associated with setting up and configuring a Drupal site. It’s easy to miss a step when installing and configuring the same site structure over and over again. Installation profiles remedy that problem by automating the process.

In this chapter, I covered the files associated with creating a new installation profile, the structure and content of each of those files, and the details of the configuration options associated with creating and enabling core features such as blocks, content types, fields, taxonomy, and user roles.

544

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]