Advertising sustains the DA. Ads are hidden for members. Join today

Using restore hooks

Last updated on
30 April 2025

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

Additional to the script files, theres a hook too allow a module to provide its own programatically generated restore script, using "hook_restore_scripts" and returning an array of restore scripts: Note that the properties of the operations required depends on the operation classes.

/**
* Implements hook_restore_scripts().
*/
function MY_MODULE_restore_scripts() {
  $scripts = array();

  $scripts['example_script_1'] = array(
    // The title for the restore script.
    'title' => 'MY MODULES SCRIPT #1',

    // A description for the restore script.
    'description' => 'The first restore script provided by MY MODULE.',

    // An array of the operations, indexed by the operations classname.
    'operations' => array(

      // Some variables.
      'RestoreVariableOperation' => array(

        array(
          'name' => 'some_random_variable_name',
          'value' => 'a random value.',
        ),

        array(
          'name' => 'site_name',
          'value' => 'The name of my site.',
        ),

        array(
          'name' => 'clean_urls',
          'value' => TRUE,
        ),

      ),

    ),
  );

  $scripts['example_script_2'] = array(
  );

  return $scripts;
}

An example module is provided showing this usage, "restore_example_hook" in the module/examples folder.

Help improve this page

Page status: Not set

You can: