taxonomy.rules.inc 3.9 KB

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