diff --git a/modules/events.inc b/modules/events.inc index 87e8fa2..9bdc602 100644 --- a/modules/events.inc +++ b/modules/events.inc @@ -25,134 +25,103 @@ function rules_events_entity_unchanged($arguments, $name, $info) { } /** - * Node events - * For getting the unchanged node we currently have to implement a workaround. - * If http://drupal.org/node/651240 gets in, we can simplify that. + * Generic entity events, used only for core-entities for which we provide + * Rules integration. + * We are implementing the generic-entity events instead of the entity-type + * specific events to ensure we come last. See http://drupal.org/node/1211946 + * for details. */ -function rules_node_view($node, $view_mode) { - rules_invoke_event('node_view', $node, $view_mode); -} - -function rules_node_presave($node) { - rules_invoke_event('node_presave', $node); -} - -function rules_node_update($node) { - rules_invoke_event('node_update', $node); -} - -function rules_node_insert($node) { - rules_invoke_event('node_insert', $node); -} - -function rules_node_delete($node) { - rules_invoke_event('node_delete', $node); -} - - - /** - * Invoke user events. + * Implements hook_entity_view(). */ - -function rules_user_view($account, $view_mode) { - rules_invoke_event('user_view', $account, $view_mode); +function rules_entity_view($entity, $type, $view_mode, $langcode) { + $entity_types = array( + 'comment' => TRUE, + 'node' => TRUE, + 'user' => TRUE, + ); + if (isset($entity_types[$type])) { + rules_invoke_event($type . '_view', $entity, $view_mode); + } } /** - * We don't want to use hook_user_presave() here as it would requires us - * to mess with the $edit array to get an updated $account. + * Implements hook_entity_presave(). */ -function rules_entity_presave($entity, $entity_type) { - if ($entity_type == 'user') { - rules_invoke_event('user_presave', $entity); +function rules_entity_presave($entity, $type) { + $entity_types = array( + 'comment' => TRUE, + 'node' => TRUE, + 'taxonomy_term' => TRUE, + 'taxonomy_vocabulary' => TRUE, + 'user' => TRUE, + ); + if (isset($entity_types[$type])) { + rules_invoke_event($type . '_presave', $entity); } } -function rules_user_insert(&$edit, $account, $category) { - if ($category == 'account') { - rules_invoke_event('user_insert', $account); +/** + * Implements hook_entity_update(). + */ +function rules_entity_update($entity, $type) { + $entity_types = array( + 'comment' => TRUE, + 'node' => TRUE, + 'taxonomy_term' => TRUE, + 'taxonomy_vocabulary' => TRUE, + 'user' => TRUE, + ); + if (isset($entity_types[$type])) { + rules_invoke_event($type . '_update', $entity); } } -function rules_user_update(&$edit, $account, $category) { - if ($category == 'account') { - rules_invoke_event('user_update', $account); +/** + * Implements hook_entity_insert(). + */ +function rules_entity_insert($entity, $type) { + $entity_types = array( + 'comment' => TRUE, + 'node' => TRUE, + 'taxonomy_term' => TRUE, + 'taxonomy_vocabulary' => TRUE, + 'user' => TRUE, + ); + if (isset($entity_types[$type])) { + rules_invoke_event($type . '_insert', $entity); } } -function rules_user_delete($account) { - rules_invoke_event('user_delete', $account); -} - -function rules_user_login(&$edit, $account) { - rules_invoke_event('user_login', $account); -} - -function rules_user_logout($account) { - rules_invoke_event('user_logout', $account); -} - /** - * Comment events. + * Implements hook_entity_delete(). */ - -function rules_comment_view($comment) { - rules_invoke_event('comment_view', $comment); -} - -function rules_comment_presave($comment) { - rules_invoke_event('comment_presave', $comment); -} - -function rules_comment_update($comment) { - rules_invoke_event('comment_update', $comment); -} - -function rules_comment_insert($comment) { - rules_invoke_event('comment_insert', $comment); -} - -function rules_comment_delete($comment) { - rules_invoke_event('comment_delete', $comment); +function rules_entity_delete($entity, $type) { + $entity_types = array( + 'comment' => TRUE, + 'node' => TRUE, + 'taxonomy_term' => TRUE, + 'taxonomy_vocabulary' => TRUE, + 'user' => TRUE, + ); + if (isset($entity_types[$type])) { + rules_invoke_event($type . '_delete', $entity); + } } - /** - * Taxonomy events. + * Implements hook_user_login(). */ - -function rules_taxonomy_term_update($taxonomy_term) { - rules_invoke_event('taxonomy_term_update', $taxonomy_term); -} - -function rules_taxonomy_term_presave($taxonomy_term) { - rules_invoke_event('taxonomy_term_presave', $taxonomy_term); -} - -function rules_taxonomy_term_insert($taxonomy_term) { - rules_invoke_event('taxonomy_term_insert', $taxonomy_term); -} - -function rules_taxonomy_term_delete($taxonomy_term) { - rules_invoke_event('taxonomy_term_delete', $taxonomy_term); -} - -function rules_taxonomy_vocabulary_update($taxonomy_vocabulary) { - rules_invoke_event('taxonomy_vocabulary_update', $taxonomy_vocabulary); -} - -function rules_taxonomy_vocabulary_presave($taxonomy_vocabulary) { - rules_invoke_event('taxonomy_vocabulary_presave', $taxonomy_vocabulary); -} - -function rules_taxonomy_vocabulary_insert($taxonomy_vocabulary) { - rules_invoke_event('taxonomy_vocabulary_insert', $taxonomy_vocabulary); +function rules_user_login(&$edit, $account) { + rules_invoke_event('user_login', $account); } -function rules_taxonomy_vocabulary_delete($taxonomy_vocabulary) { - rules_invoke_event('taxonomy_vocabulary_delete', $taxonomy_vocabulary); +/** + * Implements hook_user_logout(). + */ +function rules_user_logout($account) { + rules_invoke_event('user_logout', $account); } /** @@ -160,10 +129,16 @@ function rules_taxonomy_vocabulary_delete($taxonomy_vocabulary) { * invoke the init event. */ +/** + * Implements rules_cron(). + */ function rules_cron() { rules_invoke_event('cron'); } +/** + * Implements rules_watchdog(). + */ function rules_watchdog($log_entry) { rules_invoke_event('watchdog', $log_entry); }