workflow_admin_ui.module 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /**
  3. * @file
  4. * Provides administrative UI for workflow.
  5. *
  6. * Why it's own module? Lower code footprint and better performance.
  7. * Additional credit to gcassie ( http://drupal.org/user/80260 ) for
  8. * the initial push to split UI out of core workflow.
  9. * We're moving workflow in a API direction, so UI and the like - out.
  10. */
  11. // Caveat: Several hooks have moved into the EntityWorkflowUIController class.
  12. define('WORKFLOW_ADMIN_UI_ARROW', '&#8594;');
  13. /**
  14. * Implements hook_entity_info_alter().
  15. *
  16. * Adds Admin UI to entities, using EntityWorkflowUIController.
  17. */
  18. function workflow_admin_ui_entity_info_alter(&$entity_info) {
  19. $admin_path = WORKFLOW_ADMIN_UI_PATH;
  20. $entity_info['Workflow'] += array(
  21. 'access callback' => 'workflow_access',
  22. 'admin ui' => array(
  23. 'path' => $admin_path,
  24. // Do not add 'file', since each page has its own file.
  25. // 'file' => 'workflow_admin_ui/workflow_admin_ui.pages.inc',
  26. 'controller class' => 'EntityWorkflowUIController',
  27. 'menu wildcard' => '%workflow',
  28. ),
  29. );
  30. }
  31. /**
  32. * Implements hook_help().
  33. */
  34. function workflow_admin_ui_help($path, $arg) {
  35. switch ($path) {
  36. case 'admin/modules':
  37. case WORKFLOW_ADMIN_UI_PATH:
  38. if (module_exists('workflownode') && module_exists('workflowfield')) {
  39. $m = t('Do not enable Workfow Node and Workflow Field submodules at the
  40. same time (unless you are in a migration phase). Visit the <a href=
  41. "@url">modules</a> page.', array('@url' => url('admin/modules',
  42. array('fragment' => 'Workflow'))));
  43. drupal_set_message($m, 'warning');
  44. }
  45. return;
  46. case WORKFLOW_ADMIN_UI_PATH . '/add':
  47. return t('To get started, provide a name for your workflow. This name
  48. will be used as a label when the workflow status is shown during node
  49. editing.');
  50. case WORKFLOW_ADMIN_UI_PATH . '/manage/%/states':
  51. return t("To create a new state, enter its name in the last row of the
  52. 'State' column. Check the 'Active' box to make it effective. You may
  53. also drag it to the appropriate position.") . '<br />'
  54. . t("A state must be marked as active, to be available in the
  55. workflow's transitions.") . '<br />'
  56. . t("If you wish to inactivate a state that has content (i.e. count is
  57. not zero), then you need to select a state to which to reassign that
  58. content.");
  59. case WORKFLOW_ADMIN_UI_PATH . '/manage/%/transitions':
  60. return t('You are currently viewing the possible transitions to and from
  61. workflow states. The state is shown in the left column; the state to be
  62. moved to is to the right. For each transition, check the box next to
  63. the role(s) that may initiate the transition. For example, if only the
  64. "production editor" role may move a node from Review state to the
  65. Published state, check the box next to "production editor". The author
  66. role is built in and refers to the user who authored the node.')
  67. . '<br /><i>'
  68. . t("If not all roles are in the list, please review which roles may
  69. 'participate in workflows' <a href='!url'> on the Permissions page</a>.
  70. </i>",
  71. array('!url' => url('admin/people/permissions', array(
  72. 'fragment' => 'module-workflow'))));
  73. case WORKFLOW_ADMIN_UI_PATH . '/manage/%/labels':
  74. return t('You can add labels to transitions if you don\'t like the
  75. standard state labels. They will modify the Workflow form options, so
  76. specific workflow transitions can have their own labels, relative to
  77. the beginning and ending states. Rather than showing the user a
  78. workflow box containing options like "review required" as a state in
  79. the workflow, it could say "move to the editing department for grammar
  80. review".');
  81. }
  82. }
  83. /**
  84. * Implements hook_permission().
  85. */
  86. function workflow_admin_ui_permission() {
  87. return array(
  88. 'administer workflow' => array(
  89. 'title' => t('Administer workflow'),
  90. 'description' => t('Administer workflow configurations.'),
  91. ),
  92. );
  93. }
  94. function workflow_form($form, &$form_state, $workflow, $op, $entity_type) {
  95. module_load_include('inc', 'workflow_admin_ui', 'workflow_admin_ui.page.workflow');
  96. switch ($op) {
  97. case 'add':
  98. case 'edit':
  99. case 'clone':
  100. return workflow_admin_ui_edit_form($form, $form_state, $workflow, $op);
  101. case 'view':
  102. case 'delete':
  103. default:
  104. }
  105. }
  106. /**
  107. * Determines whether the given user has access to a Workflow entity.
  108. *
  109. * @param string $op
  110. * The operation being performed. One of 'view', 'update', 'create' or 'delete'.
  111. * @param object $entity
  112. * Entity to check access for. If no entity is given, it will be
  113. * determined whether access is allowed for all entities of the given type.
  114. * @param object $account
  115. * The user to check for. Leave it to NULL to check for the global user.
  116. * @param string $entity_type
  117. * The entity type.
  118. *
  119. * @return bool
  120. * Whether access is allowed or not. If the entity type does not specify any
  121. * access information, NULL is returned.
  122. */
  123. function workflow_access($op, $entity, $account, $entity_type) {
  124. return user_access('administer workflow', $account);
  125. }
  126. /**
  127. * Implements hook_theme().
  128. */
  129. function workflow_admin_ui_theme() {
  130. return array(
  131. 'workflow_admin_ui_type_map_form' => array('render element' => 'form'),
  132. 'workflow_admin_ui_states_form' => array('render element' => 'form'),
  133. 'workflow_admin_ui_transitions_form' => array('render element' => 'form'),
  134. );
  135. }
  136. /**
  137. * Helper function. Create breadcrumbs.
  138. *
  139. * @param object $workflow
  140. * The workflow object.
  141. * @param mixed $extra
  142. * Optional. The link to the extra item to add to the end of the breadcrumbs.
  143. */
  144. function workflow_admin_ui_breadcrumbs($workflow, $extra = NULL) {
  145. $bc = array(l(t('Home'), '<front>'));
  146. $bc[] = l(t('Configuration'), 'admin/config');
  147. $bc[] = l(t('Workflow'), 'admin/config/workflow');
  148. $bc[] = l(t('Workflow'), WORKFLOW_ADMIN_UI_PATH);
  149. if ($workflow) {
  150. $bc[] = l($workflow->label(), WORKFLOW_ADMIN_UI_PATH . "/$workflow->wid");
  151. }
  152. if ($extra) {
  153. $bc[] = $extra;
  154. }
  155. drupal_set_breadcrumb($bc);
  156. }