|
|
Drupal example source code file (events.inc)
The events.inc Drupal example source code<?php // $Id: events.inc,v 1.1.2.3 2011/01/05 10:49:15 fago Exp $ /** * @file Invokes events on behalf core modules. Usually this should be * directly in the module providing rules integration instead. * * @addtogroup rules * @{ */ /** * Gets an unchanged entity that doesn't contain any recent changes. This * handler assumes the name of the variable for the changed entity is the same * as for the unchanged entity but without the trailing "_unchanged"; e.g., for * the "node_unchanged" variable the handler assumes there is a "node" variable. */ function rules_events_entity_unchanged($arguments, $name, $info) { // Cut of the trailing _unchanged. $var_name = substr($name, 0, -10); $entity = $arguments[$var_name]; if (isset($entity->original)) { return $entity->original; } } /** * 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. */ 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. */ function rules_user_view($account, $view_mode) { rules_invoke_event('user_view', $account, $view_mode); } function rules_user_presave(&$edit, $account, $category) { if ($category == 'account') { rules_invoke_event('user_presave', $account); } } function rules_user_insert(&$edit, $account, $category) { if ($category == 'account') { rules_invoke_event('user_insert', $account); } } function rules_user_update(&$edit, $account, $category) { if ($category == 'account') { rules_invoke_event('user_update', $account); } } 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. */ 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); } /** * Taxonomy events. */ 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_taxonomy_vocabulary_delete($taxonomy_vocabulary) { rules_invoke_event('taxonomy_vocabulary_delete', $taxonomy_vocabulary); } /** * System events. Note that rules_init() is the main module file is used to * invoke the init event. */ function rules_cron() { rules_invoke_event('cron'); } function rules_watchdog($log_entry) { rules_invoke_event('watchdog', $log_entry); } /** * Data actions access callback. * Returns TRUE if at least one type is available for configuring the action. */ function rules_data_action_access($type, $name) { if ($name == 'entity_fetch' || $name == 'entity_create' || $name == 'entity_query') { $types = array_keys(rules_data_action_type_options($name)); $op = $name == 'entity_create' ? 'create' : 'view'; } elseif ($name == 'entity_save' || $name == 'entity_delete') { $cache = rules_get_cache(); $types = $cache['action_info'][$name]['parameter']['data']['type']; $op = $name == 'entity_save' ? 'save' : 'delete'; } foreach ($types as $key => $type) { if (!entity_access($op, $type)) { unset($types[$key]); } } return !empty($types); } /** * Getter callback for the log entry message property. */ function rules_system_log_get_message($log_entry) { return t($log_entry['message'], (array)$log_entry['variables']); } /** * @} */ Other Drupal examples (source code examples)Here is a short list of links related to this Drupal events.inc source code file: |
"Drupal" is a registered trademark of Dries Buytaert.
my drupal tutorials and examples
Copyright
1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.
Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.