workflow_views.module 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * @file
  4. * Provide views integration for workflows.
  5. *
  6. * Why it's own module? Some sites have views some don't,
  7. * all prefer a lower code footprint and better performance.
  8. */
  9. /**
  10. * Implements hook_permission().
  11. */
  12. function workflow_views_permission() {
  13. return array(
  14. 'access workflow summary views' => array(
  15. 'title' => t('Access workflow summary views'),
  16. 'description' => t('Access workflow summary views.'),
  17. ),
  18. );
  19. }
  20. /**
  21. * Implements hook_entity_info_alter().
  22. *
  23. * Create a new 'workflow_tab' view mode, to use in the workflow history tab.
  24. */
  25. function workflow_views_entity_info_alter(&$entity_info) {
  26. $field_maps = _workflow_info_fields();
  27. foreach ($field_maps as $field_name => $field_map) {
  28. foreach ($field_map['bundles'] as $entity_type => $bundles) {
  29. if (isset($entity_info[$entity_type])) {
  30. // If a module is rudely disabled, the $entity may not exist anymore.
  31. $entity_info[$entity_type]['view modes']['workflow_tab'] = array(
  32. 'label' => t('Workflow History'),
  33. 'custom settings' => FALSE,
  34. );
  35. }
  36. }
  37. }
  38. }
  39. /**
  40. * Implements hook_views_api().
  41. *
  42. * @todo D8: remove hook_views_api. See [#1875596]
  43. */
  44. function workflow_views_views_api() {
  45. return array(
  46. 'api' => 3,
  47. // The views.inc files are already in the root directory,
  48. // as required in D8.
  49. // 'path' => drupal_get_path('module', 'workflow_views'),
  50. );
  51. }
  52. /**
  53. * Implements hook_views_default_views().
  54. *
  55. * Loads all Views, custom made by this module, as stored in files xxx.view.inc.
  56. *
  57. * @see http://www.deckfifty.com/blog/2012-02/using-drupal-views-code
  58. * @see http://mc-kenna.com/drupal/2009/05/managing-drupal-views-the-proper-way
  59. * @see http://www.chapterthree.com/blog/matt_cheney/howto_best_practices_embedding_views_code
  60. *
  61. * https://api.drupal.org/api/views/views.api.php/function/hook_views_default_views/7
  62. * "This hook allows modules to provide their own views which can either be used as-is or as a "starter" for users to build from.
  63. * "This hook should be placed in MODULENAME.views_default.inc and it will be auto-loaded.
  64. * "The $view->disabled boolean flag indicates whether the View should be enabled (FALSE) or disabled (TRUE) by default.
  65. *
  66. * "A best practice is to go through and add t() to all title and label strings, with the exception of menu strings.
  67. */
  68. function workflow_views_views_default_views() {
  69. $views = array();
  70. $modulename = 'workflow_views';
  71. // Find views in this directory, and the 'views' subdirectory.
  72. $dir = drupal_get_path('module', $modulename) . '/';
  73. $regex = '/\.view\.inc$/';
  74. $files = array();
  75. $files += file_scan_directory($dir, $regex, array('recurse' => FALSE));
  76. $files += file_scan_directory($dir . 'views/', $regex, array('recurse' => FALSE));
  77. foreach ($files as $filepath => $file) {
  78. require $filepath;
  79. if (isset($view)) {
  80. $views[$view->name] = $view;
  81. }
  82. }
  83. return $views;
  84. }