hosting_task.api.php

Hooks provided by the hosting tasks module.

Functions

Namesort descending Description
hook_hosting_tasks Define tasks that can be executed in the front-end.
hook_hosting_tasks_alter Alter front-end tasks defined by other modules.
hosting_task_TASK_TYPE_form Add fields to the task confirmation form.
hosting_task_TASK_TYPE_form_validate Validate the form data defined in hosting_task_TASK_TYPE_form().

File

task/hosting_task.api.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the hosting tasks module.
  5. */
  6. /**
  7. * @addtogroup backend-frontend-IPC
  8. * @{
  9. */
  10. /**
  11. * Define tasks that can be executed in the front-end.
  12. *
  13. * @return array
  14. * An array of arrays of tasks that can be executed by the front-end.
  15. * The keys of the outer array should be the object that tasks operate on, for
  16. * example 'site', 'platform' or 'server'. The values of the outer array
  17. * should be an array of tasks keyed by task type, the value should be an
  18. * array that defines the task. Valid keys for defining tasks are:
  19. * - 'title': (required) The human readable name of the task.
  20. * - 'description': (optional) The human readable description of the task.
  21. * - 'weight': (optional) The weight of the task when displayed in lists.
  22. * - 'dialog' (optional) Set to TRUE to indicate that this task requires a
  23. * dialog to be shown to the user to confirm the execution of the task.
  24. * - 'hidden' (optional) Set to TRUE to hide the task in the front-end UI, the
  25. * task will still be available for execution by the front-end however.
  26. * - 'access callback' (optional) An access callback to determine if the user
  27. * can access the task, defaults to 'hosting_task_menu_access'.
  28. * - 'provision_save' (optional, defaults to FALSE) A flag that tells
  29. * provision that a "provision-save" command needs to happen before this
  30. * task can be run, used for tasks like Verify, Install, and Import.
  31. * If you implement this option, you should implement
  32. * hook_hosting_TASK_OBJECT_context_options() in order to pass parameters
  33. * to the provision-save command.
  34. *
  35. * @see hosting_available_tasks()
  36. * @see hosting_task_TASK_TYPE_form()
  37. */
  38. function hook_hosting_tasks() {
  39. // From hosting_clone_hosting_tasks().
  40. $options = array();
  41. $options['site']['clone'] = array(
  42. 'title' => t('Clone'),
  43. 'description' => t('Make a copy of a site.'),
  44. 'weight' => 5,
  45. 'dialog' => TRUE,
  46. );
  47. return $options;
  48. }
  49. /**
  50. * Alter front-end tasks defined by other modules.
  51. *
  52. * @param $tasks
  53. * An array of tasks defined by other modules. Keys of the outer array are the
  54. * types of objects that the tasks operate on, e.g. 'site', 'platform' or
  55. * 'server', values are arrays of the tasks that apply to those objects.
  56. *
  57. * @see hook_hosting_tasks
  58. */
  59. function hook_hosting_tasks_alter(&$tasks) {
  60. // Change the title of the site's clone task.
  61. if (isset($tasks['site']['clone'])) {
  62. $tasks['site']['clone']['title'] = t('Site clone');
  63. }
  64. }
  65. /**
  66. * Add fields to the task confirmation form.
  67. *
  68. * @param $node
  69. * The node on which the task is being called.
  70. *
  71. * @see hosting_task_confirm_form()
  72. * @see hosting_site_list_form()
  73. */
  74. function hosting_task_TASK_TYPE_form($node) {
  75. // From hosting_task_clone_form()
  76. $form = hosting_task_migrate_form($node);
  77. $form['new_uri']['#description'] = t('The new domain name of the clone site.');
  78. return $form;
  79. }
  80. /**
  81. * Validate the form data defined in hosting_task_TASK_TYPE_form().
  82. *
  83. * @see hosting_task_confirm_form()
  84. */
  85. function hosting_task_TASK_TYPE_form_validate($form, &$form_state) {
  86. // From hosting_task_clone_form_validate()
  87. $site = $form['parameters']['#node'];
  88. $url = strtolower(trim($form_state['values']['parameters']['new_uri'])); // domain names are case-insensitive
  89. if ($url == strtolower(trim($site->title))) {
  90. form_set_error('new_uri', t("To clone a site you need to specify a new Domain name to clone it to."));
  91. }
  92. else {
  93. hosting_task_migrate_form_validate($form, $form_state);
  94. }
  95. }
  96. /**
  97. * @} End of "addtogroup hooks".
  98. */