taxonomy.rules.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * @file
  4. * Rules integration for the taxonomy_term module.
  5. *
  6. * @addtogroup rules
  7. *
  8. * @{
  9. */
  10. /**
  11. * Implements hook_rules_event_info().
  12. */
  13. function rules_taxonomy_event_info() {
  14. $defaults_term = array(
  15. 'group' => t('Taxonomy'),
  16. 'access callback' => 'rules_taxonomy_term_integration_access',
  17. 'module' => 'taxonomy',
  18. 'class' => 'RulesTaxonomyEventHandler',
  19. );
  20. $defaults_vocab = array(
  21. 'group' => t('Taxonomy'),
  22. 'access callback' => 'rules_taxonomy_vocabulary_integration_access',
  23. 'module' => 'taxonomy',
  24. );
  25. return array(
  26. 'taxonomy_term_insert' => $defaults_term + array(
  27. 'label' => t('After saving a new term'),
  28. 'variables' => array(
  29. 'term' => array('type' => 'taxonomy_term', 'label' => t('created term')),
  30. ),
  31. ),
  32. 'taxonomy_term_update' => $defaults_term + array(
  33. 'label' => t('After updating an existing term'),
  34. 'variables' => array(
  35. 'term' => array('type' => 'taxonomy_term', 'label' => t('updated term')),
  36. 'term_unchanged' => array(
  37. 'type' => 'taxonomy_term',
  38. 'label' => t('unchanged term'),
  39. 'handler' => 'rules_events_entity_unchanged',
  40. ),
  41. ),
  42. ),
  43. 'taxonomy_term_presave' => $defaults_term + array(
  44. 'label' => t('Before saving a taxonomy term'),
  45. 'variables' => array(
  46. 'term' => array(
  47. 'type' => 'taxonomy_term',
  48. 'label' => t('saved term'),
  49. 'skip save' => TRUE,
  50. ),
  51. 'term_unchanged' => array(
  52. 'type' => 'taxonomy_term',
  53. 'label' => t('unchanged term'),
  54. 'handler' => 'rules_events_entity_unchanged',
  55. ),
  56. ),
  57. ),
  58. 'taxonomy_term_delete' => $defaults_term + array(
  59. 'label' => t('After deleting a term'),
  60. 'variables' => array(
  61. 'term' => array('type' => 'taxonomy_term', 'label' => t('deleted term')),
  62. ),
  63. ),
  64. 'taxonomy_vocabulary_insert' => $defaults_vocab + array(
  65. 'label' => t('After saving a new vocabulary'),
  66. 'variables' => array(
  67. 'vocabulary' => array('type' => 'taxonomy_vocabulary', 'label' => t('created vocabulary')),
  68. ),
  69. ),
  70. 'taxonomy_vocabulary_update' => $defaults_vocab + array(
  71. 'label' => t('After updating an existing vocabulary'),
  72. 'variables' => array(
  73. 'vocabulary' => array(
  74. 'type' => 'taxonomy_vocabulary',
  75. 'label' => t('updated vocabulary'),
  76. ),
  77. 'vocabulary_unchanged' => array(
  78. 'type' => 'taxonomy_vocabulary',
  79. 'label' => t('unchanged vocabulary'),
  80. 'handler' => 'rules_events_entity_unchanged',
  81. ),
  82. ),
  83. ),
  84. 'taxonomy_vocabulary_presave' => $defaults_vocab + array(
  85. 'label' => t('Before saving a vocabulary'),
  86. 'variables' => array(
  87. 'vocabulary' => array(
  88. 'type' => 'taxonomy_vocabulary',
  89. 'label' => t('saved vocabulary'),
  90. 'skip save' => TRUE,
  91. ),
  92. 'vocabulary_unchanged' => array(
  93. 'type' => 'taxonomy_vocabulary',
  94. 'label' => t('unchanged vocabulary'),
  95. 'handler' => 'rules_events_entity_unchanged',
  96. ),
  97. ),
  98. ),
  99. 'taxonomy_vocabulary_delete' => $defaults_vocab + array(
  100. 'label' => t('After deleting a vocabulary'),
  101. 'variables' => array(
  102. 'vocabulary' => array(
  103. 'type' => 'taxonomy_vocabulary',
  104. 'label' => t('deleted vocabulary'),
  105. ),
  106. ),
  107. ),
  108. );
  109. }
  110. /**
  111. * Taxonomy term integration access callback.
  112. */
  113. function rules_taxonomy_term_integration_access($type, $name) {
  114. if ($type == 'event' || $type == 'condition') {
  115. return entity_access('view', 'taxonomy_term');
  116. }
  117. }
  118. /**
  119. * Taxonomy vocabulary integration access callback.
  120. */
  121. function rules_taxonomy_vocabulary_integration_access($type, $name) {
  122. if ($type == 'event' || $type == 'condition') {
  123. return entity_access('view', 'taxonomy_vocabulary');
  124. }
  125. }
  126. /**
  127. * Event handler support taxonomy bundle event settings.
  128. */
  129. class RulesTaxonomyEventHandler extends RulesEventHandlerEntityBundle {
  130. /**
  131. * Returns the label to use for the bundle property.
  132. *
  133. * @return string
  134. * The label to use for the bundle property.
  135. */
  136. protected function getBundlePropertyLabel() {
  137. return t('vocabulary');
  138. }
  139. }
  140. /**
  141. * @}
  142. */