annotate modules/rules/rules.api.php @ 4:ce11bbd8f642

added modules
author danieleb <danielebarchiesi@me.com>
date Thu, 19 Sep 2013 10:38:44 +0100
parents
children
rev   line source
danielebarchiesi@4 1 <?php
danielebarchiesi@4 2
danielebarchiesi@4 3 /**
danielebarchiesi@4 4 * @file
danielebarchiesi@4 5 * This file contains no working PHP code; it exists to provide additional
danielebarchiesi@4 6 * documentation for doxygen as well as to document hooks in the standard
danielebarchiesi@4 7 * Drupal manner.
danielebarchiesi@4 8 */
danielebarchiesi@4 9
danielebarchiesi@4 10
danielebarchiesi@4 11 /**
danielebarchiesi@4 12 * @defgroup rules Rules module integrations.
danielebarchiesi@4 13 *
danielebarchiesi@4 14 * Module integrations with the rules module.
danielebarchiesi@4 15 *
danielebarchiesi@4 16 * The Rules developer documentation describes how modules can integrate with
danielebarchiesi@4 17 * rules: http://drupal.org/node/298486.
danielebarchiesi@4 18 */
danielebarchiesi@4 19
danielebarchiesi@4 20 /**
danielebarchiesi@4 21 * @defgroup rules_hooks Rules' hooks
danielebarchiesi@4 22 * @{
danielebarchiesi@4 23 * Hooks that can be implemented by other modules in order to extend rules.
danielebarchiesi@4 24 */
danielebarchiesi@4 25
danielebarchiesi@4 26 /**
danielebarchiesi@4 27 * Define rules compatible actions.
danielebarchiesi@4 28 *
danielebarchiesi@4 29 * This hook is required in order to add a new rules action. It should be
danielebarchiesi@4 30 * placed into the file MODULENAME.rules.inc, which gets automatically included
danielebarchiesi@4 31 * when the hook is invoked.
danielebarchiesi@4 32 *
danielebarchiesi@4 33 * However, as an alternative to implementing this hook, class based plugin
danielebarchiesi@4 34 * handlers may be provided by implementing RulesActionHandlerInterface. See
danielebarchiesi@4 35 * the interface for details.
danielebarchiesi@4 36 *
danielebarchiesi@4 37 * @return
danielebarchiesi@4 38 * An array of information about the module's provided rules actions.
danielebarchiesi@4 39 * The array contains a sub-array for each action, with the action name as
danielebarchiesi@4 40 * the key. Actions names may only contain lowercase alpha-numeric characters
danielebarchiesi@4 41 * and underscores and should be prefixed with the providing module name.
danielebarchiesi@4 42 * Possible attributes for each sub-array are:
danielebarchiesi@4 43 * - label: The label of the action. Start capitalized. Required.
danielebarchiesi@4 44 * - group: A group for this element, used for grouping the actions in the
danielebarchiesi@4 45 * interface. Should start with a capital letter and be translated.
danielebarchiesi@4 46 * Required.
danielebarchiesi@4 47 * - parameter: (optional) An array describing all parameter of the action
danielebarchiesi@4 48 * with the parameter's name as key. Each parameter has to be
danielebarchiesi@4 49 * described by a sub-array with possible attributes as described
danielebarchiesi@4 50 * afterwards, whereas the name of a parameter needs to be a lowercase,
danielebarchiesi@4 51 * valid PHP variable name.
danielebarchiesi@4 52 * - provides: (optional) An array describing the variables the action
danielebarchiesi@4 53 * provides to the evaluation state with the variable name as key. Each
danielebarchiesi@4 54 * variable has to be described by a sub-array with possible attributes as
danielebarchiesi@4 55 * described afterwards, whereas the name of a parameter needs to be a
danielebarchiesi@4 56 * lowercase, valid PHP variable name.
danielebarchiesi@4 57 * - 'named parameter': (optional) If set to TRUE, the arguments will be
danielebarchiesi@4 58 * passed as a single array with the parameter names as keys. This emulates
danielebarchiesi@4 59 * named parameters in PHP and is in particular useful if the number of
danielebarchiesi@4 60 * parameters can vary. Defaults to FALSE.
danielebarchiesi@4 61 * - base: (optional) The base for action implementation callbacks to use
danielebarchiesi@4 62 * instead of the action's name. Defaults to the action name.
danielebarchiesi@4 63 * - callbacks: (optional) An array which allows to set specific function
danielebarchiesi@4 64 * callbacks for the action. The default for each callback is the actions
danielebarchiesi@4 65 * base appended by '_' and the callback name.
danielebarchiesi@4 66 * - 'access callback': (optional) A callback which has to return whether the
danielebarchiesi@4 67 * currently logged in user is allowed to configure this action. See
danielebarchiesi@4 68 * rules_node_integration_access() for an example callback.
danielebarchiesi@4 69 * Each 'parameter' array may contain the following properties:
danielebarchiesi@4 70 * - label: The label of the parameter. Start capitalized. Required.
danielebarchiesi@4 71 * - type: The rules data type of the parameter, which is to be passed to the
danielebarchiesi@4 72 * action. All types declared in hook_rules_data_info() may be specified, as
danielebarchiesi@4 73 * well as an array of possible types. Also lists and lists of a given type
danielebarchiesi@4 74 * can be specified by using the notating list<integer> as introduced by
danielebarchiesi@4 75 * the entity metadata module, see hook_entity_property_info(). The special
danielebarchiesi@4 76 * keyword '*' can be used when all types should be allowed. Required.
danielebarchiesi@4 77 * - bundles: (optional) An array of bundle names. When the specified type is
danielebarchiesi@4 78 * set to a single entity type, this may be used to restrict the allowed
danielebarchiesi@4 79 * bundles.
danielebarchiesi@4 80 * - description: (optional) If necessary, a further description of the
danielebarchiesi@4 81 * parameter.
danielebarchiesi@4 82 * - options list: (optional) A callback that returns an array of possible
danielebarchiesi@4 83 * values for this parameter. The callback has to return an array as used
danielebarchiesi@4 84 * by hook_options_list(). For an example implementation see
danielebarchiesi@4 85 * rules_data_action_type_options().
danielebarchiesi@4 86 * - save: (optional) If this is set to TRUE, the parameter will be saved by
danielebarchiesi@4 87 * rules when the rules evaluation ends. This is only supported for savable
danielebarchiesi@4 88 * data types. If the action returns FALSE, saving is skipped.
danielebarchiesi@4 89 * - optional: (optional) May be set to TRUE, when the parameter isn't
danielebarchiesi@4 90 * required.
danielebarchiesi@4 91 * - 'default value': (optional) The value to pass to the action, in case the
danielebarchiesi@4 92 * parameter is optional and there is no specified value.
danielebarchiesi@4 93 * - 'allow null': (optional) Usually Rules will not pass any NULL values as
danielebarchiesi@4 94 * argument, but abort the evaluation if a NULL value is present. If set to
danielebarchiesi@4 95 * TRUE, Rules will not abort and pass the NULL value through. Defaults to
danielebarchiesi@4 96 * FALSE.
danielebarchiesi@4 97 * - restriction: (optional) Restrict how the argument for this parameter may
danielebarchiesi@4 98 * be provided. Supported values are 'selector' and 'input'.
danielebarchiesi@4 99 * - default mode: (optional) Customize the default mode for providing the
danielebarchiesi@4 100 * argument value for a parameter. Supported values are 'selector' and
danielebarchiesi@4 101 * 'input'. The default depends on the required data type.
danielebarchiesi@4 102 * - sanitize: (optional) Allows parameters of type 'text' to demand an
danielebarchiesi@4 103 * already sanitized argument. If enabled, any user specified value won't be
danielebarchiesi@4 104 * sanitized itself, but replacements applied by input evaluators are as
danielebarchiesi@4 105 * well as values retrieved from selected data sources.
danielebarchiesi@4 106 * - translatable: (optional) If set to TRUE, the provided argument value
danielebarchiesi@4 107 * of the parameter is translatable via i18n String translation. This is
danielebarchiesi@4 108 * applicable for textual parameters only, i.e. parameters of type 'text',
danielebarchiesi@4 109 * 'token', 'list<text>' and 'list<token>'. Defaults to FALSE.
danielebarchiesi@4 110 * - ui class: (optional) Allows overriding the UI class, which is used to
danielebarchiesi@4 111 * generate the configuration UI of a parameter. Defaults to the UI class of
danielebarchiesi@4 112 * the specified data type.
danielebarchiesi@4 113 * - cleaning callback: (optional) A callback that input evaluators may use
danielebarchiesi@4 114 * to clean inserted replacements; e.g. this is used by the token evaluator.
danielebarchiesi@4 115 * - wrapped: (optional) Set this to TRUE in case the data should be passed
danielebarchiesi@4 116 * wrapped. This only applies to wrapped data types, e.g. entities.
danielebarchiesi@4 117 * Each 'provides' array may contain the following properties:
danielebarchiesi@4 118 * - label: The label of the variable. Start capitalized. Required.
danielebarchiesi@4 119 * - type: The rules data type of the variable. All types declared in
danielebarchiesi@4 120 * hook_rules_data_info() may be specified. Types may be parametrized e.g.
danielebarchiesi@4 121 * the types node<page> or list<integer> are valid.
danielebarchiesi@4 122 * - save: (optional) If this is set to TRUE, the provided variable is saved
danielebarchiesi@4 123 * by rules when the rules evaluation ends. Only possible for savable data
danielebarchiesi@4 124 * types. Defaults to FALSE.
danielebarchiesi@4 125 *
danielebarchiesi@4 126 * The module has to provide an implementation for each action, being a
danielebarchiesi@4 127 * function named as specified in the 'base' key or for the execution callback.
danielebarchiesi@4 128 * All other possible callbacks are optional.
danielebarchiesi@4 129 * Supported action callbacks by rules are defined and documented in the
danielebarchiesi@4 130 * RulesPluginImplInterface. However any module may extend the action plugin
danielebarchiesi@4 131 * based upon a defined interface using hook_rules_plugin_info(). All methods
danielebarchiesi@4 132 * defined in those interfaces can be overridden by the action implementation.
danielebarchiesi@4 133 * The callback implementations for those interfaces may reside in any file
danielebarchiesi@4 134 * specified in hook_rules_file_info().
danielebarchiesi@4 135 *
danielebarchiesi@4 136 * @see hook_rules_file_info()
danielebarchiesi@4 137 * @see rules_action_execution_callback()
danielebarchiesi@4 138 * @see hook_rules_plugin_info()
danielebarchiesi@4 139 * @see RulesPluginImplInterface
danielebarchiesi@4 140 */
danielebarchiesi@4 141 function hook_rules_action_info() {
danielebarchiesi@4 142 return array(
danielebarchiesi@4 143 'mail_user' => array(
danielebarchiesi@4 144 'label' => t('Send a mail to a user'),
danielebarchiesi@4 145 'parameter' => array(
danielebarchiesi@4 146 'user' => array('type' => 'user', 'label' => t('Recipient')),
danielebarchiesi@4 147 ),
danielebarchiesi@4 148 'group' => t('System'),
danielebarchiesi@4 149 'base' => 'rules_action_mail_user',
danielebarchiesi@4 150 'callbacks' => array(
danielebarchiesi@4 151 'validate' => 'rules_action_custom_validation',
danielebarchiesi@4 152 'help' => 'rules_mail_help',
danielebarchiesi@4 153 ),
danielebarchiesi@4 154 ),
danielebarchiesi@4 155 );
danielebarchiesi@4 156 }
danielebarchiesi@4 157
danielebarchiesi@4 158 /**
danielebarchiesi@4 159 * Define categories for Rules items, e.g. actions, conditions or events.
danielebarchiesi@4 160 *
danielebarchiesi@4 161 * Categories are similar to the previously used 'group' key in e.g.
danielebarchiesi@4 162 * hook_rules_action_info(), but have a machine name and some more optional
danielebarchiesi@4 163 * keys like a weight, or an icon.
danielebarchiesi@4 164 *
danielebarchiesi@4 165 * For best compatibility, modules may keep using the 'group' key for referring
danielebarchiesi@4 166 * to categories. However, if a 'group' key and a 'category' is given the group
danielebarchiesi@4 167 * will be treated as grouping in the given category (e.g. group "paypal" in
danielebarchiesi@4 168 * category "commerce payment").
danielebarchiesi@4 169 *
danielebarchiesi@4 170 * @return
danielebarchiesi@4 171 * An array of information about the module's provided categories.
danielebarchiesi@4 172 * The array contains a sub-array for each category, with the category name as
danielebarchiesi@4 173 * the key. Names may only contain lowercase alpha-numeric characters
danielebarchiesi@4 174 * and underscores and should be prefixed with the providing module name.
danielebarchiesi@4 175 * Possible attributes for each sub-array are:
danielebarchiesi@4 176 * - label: The label of the category. Start capitalized. Required.
danielebarchiesi@4 177 * - weight: (optional) A weight for sorting the category. Defaults to 0.
danielebarchiesi@4 178 * - equals group: (optional) For BC, categories may be defined that equal
danielebarchiesi@4 179 * a previsouly used 'group'.
danielebarchiesi@4 180 * - icon: (optional) The file path of an icon to use, relative to the module
danielebarchiesi@4 181 * or specified icon path. The icon should be a transparent SVG containing
danielebarchiesi@4 182 * no colors (only #fff). See https://drupal.org/node/2090265 for
danielebarchiesi@4 183 * instructions on how to create a suiting icon.
danielebarchiesi@4 184 * Note that the icon is currently not used by Rules, however other UIs
danielebarchiesi@4 185 * building upon Rules (like fluxkraft) do, and future releases of Rules
danielebarchiesi@4 186 * might do as well. Consequently, the definition of an icon is optional.
danielebarchiesi@4 187 * However, if both an icon font and icon is given, the icon is preferred.
danielebarchiesi@4 188 * - icon path: (optional) The base path for the icon. Defaults to the
danielebarchiesi@4 189 * providing module's directory.
danielebarchiesi@4 190 * - icon font class: (optional) An icon font class referring to a suiting
danielebarchiesi@4 191 * icon. Icon font class names should map to the ones as defined by Font
danielebarchiesi@4 192 * Awesome, while themes might want to choose to provide another icon font.
danielebarchiesi@4 193 * See http://fortawesome.github.io/Font-Awesome/cheatsheet/.
danielebarchiesi@4 194 * - icon background color: (optional) The color used as icon background.
danielebarchiesi@4 195 * Should have a high contrast to white. Defaults to #ddd.
danielebarchiesi@4 196 */
danielebarchiesi@4 197 function hook_rules_category_info() {
danielebarchiesi@4 198 return array(
danielebarchiesi@4 199 'rules_data' => array(
danielebarchiesi@4 200 'label' => t('Data'),
danielebarchiesi@4 201 'equals group' => t('Data'),
danielebarchiesi@4 202 'weight' => -50,
danielebarchiesi@4 203 ),
danielebarchiesi@4 204 'fluxtwitter' => array(
danielebarchiesi@4 205 'label' => t('Twitter'),
danielebarchiesi@4 206 'icon font class' => 'icon-twitter',
danielebarchiesi@4 207 'icon font background color' => '#30a9fd',
danielebarchiesi@4 208 ),
danielebarchiesi@4 209 );
danielebarchiesi@4 210 }
danielebarchiesi@4 211
danielebarchiesi@4 212 /**
danielebarchiesi@4 213 * Specify files containing rules integration code.
danielebarchiesi@4 214 *
danielebarchiesi@4 215 * All files specified in that hook will be included when rules looks for
danielebarchiesi@4 216 * existing callbacks for any plugin. Rules remembers which callback is found in
danielebarchiesi@4 217 * which file and automatically includes the right file before it is executing
danielebarchiesi@4 218 * a plugin method callback. The file yourmodule.rules.inc is added by default
danielebarchiesi@4 219 * and need not be specified here.
danielebarchiesi@4 220 * This allows you to add new include files only containing functions serving as
danielebarchiesi@4 221 * plugin method callbacks in any file without having to care about file
danielebarchiesi@4 222 * inclusion.
danielebarchiesi@4 223 *
danielebarchiesi@4 224 * @return
danielebarchiesi@4 225 * An array of file names without the file ending which defaults to '.inc'.
danielebarchiesi@4 226 */
danielebarchiesi@4 227 function hook_rules_file_info() {
danielebarchiesi@4 228 return array('yourmodule.rules-eval');
danielebarchiesi@4 229 }
danielebarchiesi@4 230
danielebarchiesi@4 231 /**
danielebarchiesi@4 232 * Specifies directories for class-based plugin handler discovery.
danielebarchiesi@4 233 *
danielebarchiesi@4 234 * Implementing this hook is not a requirement, it is just one option to load
danielebarchiesi@4 235 * the files containing the classes during discovery - see
danielebarchiesi@4 236 * rules_discover_plugins().
danielebarchiesi@4 237 *
danielebarchiesi@4 238 * @return string|array
danielebarchiesi@4 239 * A directory relative to the module directory, which holds the files
danielebarchiesi@4 240 * containing rules plugin handlers, or multiple directories keyed by the
danielebarchiesi@4 241 * module the directory is contained in.
danielebarchiesi@4 242 * All files in those directories having a 'php' or 'inc' file extension will
danielebarchiesi@4 243 * be loaded during discovery. Optionally, wildcards ('*') may be used to
danielebarchiesi@4 244 * match multiple directories.
danielebarchiesi@4 245 *
danielebarchiesi@4 246 * @see rules_discover_plugins()
danielebarchiesi@4 247 */
danielebarchiesi@4 248 function hook_rules_directory() {
danielebarchiesi@4 249 return 'lib/Drupal/fluxtwitter/Rules/*';
danielebarchiesi@4 250 }
danielebarchiesi@4 251
danielebarchiesi@4 252 /**
danielebarchiesi@4 253 * The execution callback for an action.
danielebarchiesi@4 254 *
danielebarchiesi@4 255 * It should be placed in any file included by your module or in a file
danielebarchiesi@4 256 * specified using hook_rules_file_info().
danielebarchiesi@4 257 *
danielebarchiesi@4 258 * @param
danielebarchiesi@4 259 * The callback gets arguments passed as described as parameter in
danielebarchiesi@4 260 * hook_rules_action_info() as well as an array containing the action's
danielebarchiesi@4 261 * configuration settings.
danielebarchiesi@4 262 * @return
danielebarchiesi@4 263 * The action may return an array containg parameter or provided variables
danielebarchiesi@4 264 * with their names as key. This is used update the value of a parameter or to
danielebarchiesi@4 265 * provdide the value for a provided variable.
danielebarchiesi@4 266 * Apart from that any parameters which have the key 'save' set to TRUE will
danielebarchiesi@4 267 * be remembered to be saved by rules unless the action returns FALSE.
danielebarchiesi@4 268 * Conditions have to return a boolean value in any case.
danielebarchiesi@4 269 *
danielebarchiesi@4 270 * @see hook_rules_action_info()
danielebarchiesi@4 271 * @see hook_rules_file_info()
danielebarchiesi@4 272 */
danielebarchiesi@4 273 function rules_action_execution_callback($node, $title, $settings) {
danielebarchiesi@4 274 $node->title = $title;
danielebarchiesi@4 275 return array('node' => $node);
danielebarchiesi@4 276 }
danielebarchiesi@4 277
danielebarchiesi@4 278 /**
danielebarchiesi@4 279 * Define rules conditions.
danielebarchiesi@4 280 *
danielebarchiesi@4 281 * This hook is required in order to add a new rules condition. It should be
danielebarchiesi@4 282 * placed into the file MODULENAME.rules.inc, which gets automatically included
danielebarchiesi@4 283 * when the hook is invoked.
danielebarchiesi@4 284 *
danielebarchiesi@4 285 * However, as an alternative to implementing this hook, class based plugin
danielebarchiesi@4 286 * handlers may be provided by implementing RulesConditionHandlerInterface. See
danielebarchiesi@4 287 * the interface for details.
danielebarchiesi@4 288 *
danielebarchiesi@4 289 * Adding conditions works exactly the same way as adding actions, with the
danielebarchiesi@4 290 * exception that conditions can't provide variables and cannot save parameters.
danielebarchiesi@4 291 * Thus the 'provides' attribute is not supported. Furthermore the condition
danielebarchiesi@4 292 * implementation callback has to return a boolean value.
danielebarchiesi@4 293 *
danielebarchiesi@4 294 * @see hook_rules_action_info()
danielebarchiesi@4 295 */
danielebarchiesi@4 296 function hook_rules_condition_info() {
danielebarchiesi@4 297 return array(
danielebarchiesi@4 298 'rules_condition_text_compare' => array(
danielebarchiesi@4 299 'label' => t('Textual comparison'),
danielebarchiesi@4 300 'parameter' => array(
danielebarchiesi@4 301 'text1' => array('label' => t('Text 1'), 'type' => 'text'),
danielebarchiesi@4 302 'text2' => array('label' => t('Text 2'), 'type' => 'text'),
danielebarchiesi@4 303 ),
danielebarchiesi@4 304 'group' => t('Rules'),
danielebarchiesi@4 305 ),
danielebarchiesi@4 306 );
danielebarchiesi@4 307 }
danielebarchiesi@4 308
danielebarchiesi@4 309 /**
danielebarchiesi@4 310 * Define rules events.
danielebarchiesi@4 311 *
danielebarchiesi@4 312 * This hook is required in order to add a new rules event. It should be
danielebarchiesi@4 313 * placed into the file MODULENAME.rules.inc, which gets automatically included
danielebarchiesi@4 314 * when the hook is invoked.
danielebarchiesi@4 315 * The module has to invoke the event when it occurs using rules_invoke_event().
danielebarchiesi@4 316 * This function call has to happen outside of MODULENAME.rules.inc,
danielebarchiesi@4 317 * usually it's invoked directly from the providing module but wrapped by a
danielebarchiesi@4 318 * module_exists('rules') check.
danielebarchiesi@4 319 *
danielebarchiesi@4 320 * However, as an alternative to implementing this hook, class based event
danielebarchiesi@4 321 * handlers may be provided by implementing RulesEventHandlerInterface. See
danielebarchiesi@4 322 * the interface for details.
danielebarchiesi@4 323 *
danielebarchiesi@4 324 * @return
danielebarchiesi@4 325 * An array of information about the module's provided rules events. The array
danielebarchiesi@4 326 * contains a sub-array for each event, with the event name as the key. The
danielebarchiesi@4 327 * name may only contain lower case alpha-numeric characters and underscores
danielebarchiesi@4 328 * and should be prefixed with the providing module name. Possible attributes
danielebarchiesi@4 329 * for each sub-array are:
danielebarchiesi@4 330 * - label: The label of the event. Start capitalized. Required.
danielebarchiesi@4 331 * - group: A group for this element, used for grouping the events in the
danielebarchiesi@4 332 * interface. Should start with a capital letter and be translated.
danielebarchiesi@4 333 * Required.
danielebarchiesi@4 334 * - class: (optional) An event handler class implementing the
danielebarchiesi@4 335 * RulesEventHandlerInterface. If none is specified the
danielebarchiesi@4 336 * RulesEventDefaultHandler class will be used. While the default event
danielebarchiesi@4 337 * handler has no settings, custom event handlers may be implemented to
danielebarchiesi@4 338 * to make an event configurable. See RulesEventHandlerInterface.
danielebarchiesi@4 339 * - access callback: (optional) An callback, which has to return whether the
danielebarchiesi@4 340 * currently logged in user is allowed to configure rules for this event.
danielebarchiesi@4 341 * Access should be only granted, if the user at least may access all the
danielebarchiesi@4 342 * variables provided by the event.
danielebarchiesi@4 343 * - help: (optional) A help text for rules reaction on this event.
danielebarchiesi@4 344 * - variables: (optional) An array describing all variables that are
danielebarchiesi@4 345 * available for elements reacting on this event. Each variable has to be
danielebarchiesi@4 346 * described by a sub-array with the possible attributes:
danielebarchiesi@4 347 * - label: The label of the variable. Start capitalized. Required.
danielebarchiesi@4 348 * - type: The rules data type of the variable. All types declared in
danielebarchiesi@4 349 * hook_rules_data_info() or supported by hook_entity_property_info() may
danielebarchiesi@4 350 * be specified.
danielebarchiesi@4 351 * - bundle: (optional) If the type is an entity type, the bundle of the
danielebarchiesi@4 352 * entity.
danielebarchiesi@4 353 * - description: (optional) A description for the variable.
danielebarchiesi@4 354 * - 'options list': (optional) A callback that returns an array of possible
danielebarchiesi@4 355 * values for this variable as specified for entity properties at
danielebarchiesi@4 356 * hook_entity_property_info().
danielebarchiesi@4 357 * - 'skip save': (optional) If the variable is saved after the event has
danielebarchiesi@4 358 * occurred anyway, set this to TRUE. So rules won't save the variable a
danielebarchiesi@4 359 * second time. Defaults to FALSE.
danielebarchiesi@4 360 * - handler: (optional) A handler to load the actual variable value. This
danielebarchiesi@4 361 * is useful for lazy loading variables. The handler gets all so far
danielebarchiesi@4 362 * available variables passed in the order as defined. Also see
danielebarchiesi@4 363 * http://drupal.org/node/884554.
danielebarchiesi@4 364 * Note that for lazy-loading entities just the entity id may be passed
danielebarchiesi@4 365 * as variable value, so a handler is not necessary in that case.
danielebarchiesi@4 366 *
danielebarchiesi@4 367 * @see rules_invoke_event()
danielebarchiesi@4 368 */
danielebarchiesi@4 369 function hook_rules_event_info() {
danielebarchiesi@4 370 $items = array(
danielebarchiesi@4 371 'node_insert' => array(
danielebarchiesi@4 372 'label' => t('After saving new content'),
danielebarchiesi@4 373 'group' => t('Node'),
danielebarchiesi@4 374 'variables' => rules_events_node_variables(t('created content')),
danielebarchiesi@4 375 ),
danielebarchiesi@4 376 'node_update' => array(
danielebarchiesi@4 377 'label' => t('After updating existing content'),
danielebarchiesi@4 378 'group' => t('Node'),
danielebarchiesi@4 379 'variables' => rules_events_node_variables(t('updated content'), TRUE),
danielebarchiesi@4 380 ),
danielebarchiesi@4 381 'node_presave' => array(
danielebarchiesi@4 382 'label' => t('Content is going to be saved'),
danielebarchiesi@4 383 'group' => t('Node'),
danielebarchiesi@4 384 'variables' => rules_events_node_variables(t('saved content'), TRUE),
danielebarchiesi@4 385 ),
danielebarchiesi@4 386 'node_view' => array(
danielebarchiesi@4 387 'label' => t('Content is going to be viewed'),
danielebarchiesi@4 388 'group' => t('Node'),
danielebarchiesi@4 389 'variables' => rules_events_node_variables(t('viewed content')) + array(
danielebarchiesi@4 390 'view_mode' => array('type' => 'text', 'label' => t('view mode')),
danielebarchiesi@4 391 ),
danielebarchiesi@4 392 ),
danielebarchiesi@4 393 'node_delete' => array(
danielebarchiesi@4 394 'label' => t('After deleting content'),
danielebarchiesi@4 395 'group' => t('Node'),
danielebarchiesi@4 396 'variables' => rules_events_node_variables(t('deleted content')),
danielebarchiesi@4 397 ),
danielebarchiesi@4 398 );
danielebarchiesi@4 399 // Specify that on presave the node is saved anyway.
danielebarchiesi@4 400 $items['node_presave']['variables']['node']['skip save'] = TRUE;
danielebarchiesi@4 401 return $items;
danielebarchiesi@4 402 }
danielebarchiesi@4 403
danielebarchiesi@4 404 /**
danielebarchiesi@4 405 * Define rules data types.
danielebarchiesi@4 406 *
danielebarchiesi@4 407 * This hook is required in order to add a new rules data type. It should be
danielebarchiesi@4 408 * placed into the file MODULENAME.rules.inc, which gets automatically included
danielebarchiesi@4 409 * when the hook is invoked.
danielebarchiesi@4 410 * Rules builds upon the entity metadata module, thus to improve the support of
danielebarchiesi@4 411 * your data in rules, make it an entity if possible and provide metadata about
danielebarchiesi@4 412 * its properties and CRUD functions by integrating with the entity metadata
danielebarchiesi@4 413 * module.
danielebarchiesi@4 414 * For a list of data types defined by rules see rules_rules_core_data_info().
danielebarchiesi@4 415 *
danielebarchiesi@4 416 *
danielebarchiesi@4 417 * @return
danielebarchiesi@4 418 * An array of information about the module's provided data types. The array
danielebarchiesi@4 419 * contains a sub-array for each data type, with the data type name as the
danielebarchiesi@4 420 * key. The name may only contain lower case alpha-numeric characters and
danielebarchiesi@4 421 * underscores and should be prefixed with the providing module name. Possible
danielebarchiesi@4 422 * attributes for each sub-array are:
danielebarchiesi@4 423 * - label: The label of the data type. Start uncapitalized. Required.
danielebarchiesi@4 424 * - parent: (optional) A parent type may be set to specify a sub-type
danielebarchiesi@4 425 * relationship, which will be only used for checking compatible types. E.g.
danielebarchiesi@4 426 * the 'entity' data type is parent of the 'node' data type, thus a node may
danielebarchiesi@4 427 * be also used for any action needing an 'entity' parameter. Can be set to
danielebarchiesi@4 428 * any known rules data type.
danielebarchiesi@4 429 * - ui class: (optional) Specify a class that is used to generate the
danielebarchiesi@4 430 * configuration UI to configure parameters of this type. The given class
danielebarchiesi@4 431 * must extend RulesDataUI and may implement the
danielebarchiesi@4 432 * RulesDataDirectInputFormInterface in order to allow the direct data input
danielebarchiesi@4 433 * configuration mode. For supporting selecting values from options lists,
danielebarchiesi@4 434 * the UI class may implement RulesDataInputOptionsListInterface also.
danielebarchiesi@4 435 * Defaults to RulesDataUI.
danielebarchiesi@4 436 * - wrap: (optional) If set to TRUE, the data is wrapped internally using
danielebarchiesi@4 437 * wrappers provided by the entity API module. This is required for entities
danielebarchiesi@4 438 * and data structures to support selecting a property via the data selector
danielebarchiesi@4 439 * and for intelligent saving.
danielebarchiesi@4 440 * - is wrapped: (optional) In case the data wrapper is already wrapped when
danielebarchiesi@4 441 * passed to Rules and Rules should not unwrap it when passing the data as
danielebarchiesi@4 442 * argument, e.g. to an action, set this to TRUE. The default FALSE is fine
danielebarchiesi@4 443 * in most cases.
danielebarchiesi@4 444 * - wrapper class: (optional) Allows the specification of a custom wrapper
danielebarchiesi@4 445 * class, which has to inherit from 'EntityMetadataWrapper'. If given Rules
danielebarchiesi@4 446 * makes use of the class for wrapping the data of the given type. However
danielebarchiesi@4 447 * note that if data is already wrapped when it is passed to Rules, the
danielebarchiesi@4 448 * existing wrappers will be kept.
danielebarchiesi@4 449 * For modules implementing identifiable data types being non-entites the
danielebarchiesi@4 450 * class RulesIdentifiableDataWrapper is provided, which can be used as base
danielebarchiesi@4 451 * for a custom wrapper class. See RulesIdentifiableDataWrapper for details.
danielebarchiesi@4 452 * - property info: (optional) May be used for non-entity data structures to
danielebarchiesi@4 453 * provide info about the data properties, such that data selectors via an
danielebarchiesi@4 454 * entity metadata wrapper are supported. Specify an array as expected by
danielebarchiesi@4 455 * the $info parameter of entity_metadata_wrapper().
danielebarchiesi@4 456 * - creation callback: (optional) If 'property info' is given, an optional
danielebarchiesi@4 457 * callback that makes use of the property info to create a new instance of
danielebarchiesi@4 458 * this data type. Entities should use hook_entity_info() to specify the
danielebarchiesi@4 459 * 'creation callback' instead, as utilized by the entity API module. See
danielebarchiesi@4 460 * rules_action_data_create_array() for an example callback.
danielebarchiesi@4 461 * - property defaults: (optional) May be used for non-entity data structures
danielebarchiesi@4 462 * to to provide property info defaults for the data properties. Specify an
danielebarchiesi@4 463 * array as expected by entity_metadata_wrapper().
danielebarchiesi@4 464 * - group: (optional) A group for this element, used for grouping the data
danielebarchiesi@4 465 * types in the interface. Should start with a capital letter and be
danielebarchiesi@4 466 * translated.
danielebarchiesi@4 467 * - token type: (optional) The type name as used by the token module.
danielebarchiesi@4 468 * Defaults to the type name as used by rules. Use FALSE to let token ignore
danielebarchiesi@4 469 * this type.
danielebarchiesi@4 470 * - cleaning callback: (optional) A callback that input evaluators may use
danielebarchiesi@4 471 * to clean inserted replacements; e.g. this is used by the token evaluator.
danielebarchiesi@4 472 *
danielebarchiesi@4 473 * @see entity_metadata_wrapper()
danielebarchiesi@4 474 * @see hook_rules_data_info_alter()
danielebarchiesi@4 475 * @see rules_rules_core_data_info()
danielebarchiesi@4 476 */
danielebarchiesi@4 477 function hook_rules_data_info() {
danielebarchiesi@4 478 return array(
danielebarchiesi@4 479 'node' => array(
danielebarchiesi@4 480 'label' => t('content'),
danielebarchiesi@4 481 'parent' => 'entity',
danielebarchiesi@4 482 'group' => t('Node'),
danielebarchiesi@4 483 ),
danielebarchiesi@4 484 // Formatted text as used by in hook_entity_property_info() for text fields.
danielebarchiesi@4 485 'text_formatted' => array(
danielebarchiesi@4 486 'label' => t('formatted text'),
danielebarchiesi@4 487 'ui class' => 'RulesDataUITextFormatted',
danielebarchiesi@4 488 'wrap' => TRUE,
danielebarchiesi@4 489 'property info' => entity_property_text_formatted_info(),
danielebarchiesi@4 490 ),
danielebarchiesi@4 491 );
danielebarchiesi@4 492 }
danielebarchiesi@4 493
danielebarchiesi@4 494 /**
danielebarchiesi@4 495 * Defines rules plugins.
danielebarchiesi@4 496 *
danielebarchiesi@4 497 * A rules configuration may consist of elements being instances of any rules
danielebarchiesi@4 498 * plugin. This hook can be used to define new or to extend rules plugins.
danielebarchiesi@4 499 *
danielebarchiesi@4 500 * @return
danielebarchiesi@4 501 * An array of information about the module's provided rules plugins. The
danielebarchiesi@4 502 * array contains a sub-array for each plugin, with the plugin name as the
danielebarchiesi@4 503 * key. The name may only contain lower case alpha-numeric characters,
danielebarchiesi@4 504 * underscores and spaces and should be prefixed with the providing module
danielebarchiesi@4 505 * name. Possible attributes for
danielebarchiesi@4 506 * each sub-array are:
danielebarchiesi@4 507 * - label: A label for the plugin. Start capitalized. Required only for
danielebarchiesi@4 508 * components (see below).
danielebarchiesi@4 509 * - class: The implementation class. Has to extend the RulesPlugin class.
danielebarchiesi@4 510 * - embeddable: A container class in which elements of those plugin may be
danielebarchiesi@4 511 * embedded via the UI or FALSE to disallow embedding it via the UI. This
danielebarchiesi@4 512 * has no implications on the API level though. Common classes that are
danielebarchiesi@4 513 * used here are RulesConditionContainer and RulesActionContainer.
danielebarchiesi@4 514 * - component: If set to TRUE, the rules admin UI will list elements of those
danielebarchiesi@4 515 * plugin in the components UI and allows the creation of new components
danielebarchiesi@4 516 * based upon this plugin. Optional.
danielebarchiesi@4 517 * - extenders: This allows one to specify faces extenders, which may be used
danielebarchiesi@4 518 * to dynamically implement interfaces. Optional. All extenders specified
danielebarchiesi@4 519 * here are setup automatically by rules once the object is created. To
danielebarchiesi@4 520 * specify set this to an array, where the keys are the implemented
danielebarchiesi@4 521 * interfaces pointing to another array with the keys:
danielebarchiesi@4 522 * - class: The class of the extender, implementing the FacesExtender
danielebarchiesi@4 523 * and the specified interface. Either 'class' or 'methods' has to exist.
danielebarchiesi@4 524 * - methods: An array of callbacks that implement the methods of the
danielebarchiesi@4 525 * interface where the method names are the keys and the callback names
danielebarchiesi@4 526 * the values. There has to be a callback for each defined method.
danielebarchiesi@4 527 * - file: An optional array describing the file to include when a method
danielebarchiesi@4 528 * of the interface is invoked. The array entries known are 'type',
danielebarchiesi@4 529 * 'module', and 'name' matching the parameters of module_load_include().
danielebarchiesi@4 530 * Only 'module' is required as 'type' defaults to 'inc' and 'name' to
danielebarchiesi@4 531 * NULL.
danielebarchiesi@4 532 * - overrides: An optional array, which may be used to specify callbacks to
danielebarchiesi@4 533 * override specific methods. For that the following keys are supported:
danielebarchiesi@4 534 * - methods: As in the extenders array, but you may specify as many methods
danielebarchiesi@4 535 * here as you like.
danielebarchiesi@4 536 * - file: Optionally an array specifying a file to include for a method.
danielebarchiesi@4 537 * For each method appearing in methods a file may be specified by using
danielebarchiesi@4 538 * the method name as key and another array as value, which describes the
danielebarchiesi@4 539 * file to include - looking like the file array supported by 'extenders'.
danielebarchiesi@4 540 * - import keys: (optional) Embeddable plugins may specify an array of import
danielebarchiesi@4 541 * keys, which the plugin make use for exporting. Defaults to the upper
danielebarchiesi@4 542 * case plugin name, thus the key 'OR' in an export triggers the creation
danielebarchiesi@4 543 * of the 'or' plugin. Note that only uppercase values are allowed, as
danielebarchiesi@4 544 * lower case values are treated as action or condition exports.
danielebarchiesi@4 545 *
danielebarchiesi@4 546 * @see class RulesPlugin
danielebarchiesi@4 547 * @see hook_rules_plugin_info_alter()
danielebarchiesi@4 548 */
danielebarchiesi@4 549 function hook_rules_plugin_info() {
danielebarchiesi@4 550 return array(
danielebarchiesi@4 551 'or' => array(
danielebarchiesi@4 552 'label' => t('Condition set (OR)'),
danielebarchiesi@4 553 'class' => 'RulesOr',
danielebarchiesi@4 554 'embeddable' => 'RulesConditionContainer',
danielebarchiesi@4 555 'component' => TRUE,
danielebarchiesi@4 556 'extenders' => array(
danielebarchiesi@4 557 'RulesPluginUIInterface' => array(
danielebarchiesi@4 558 'class' => 'RulesConditionContainerUI',
danielebarchiesi@4 559 ),
danielebarchiesi@4 560 ),
danielebarchiesi@4 561 ),
danielebarchiesi@4 562 'rule' => array(
danielebarchiesi@4 563 'class' => 'Rule',
danielebarchiesi@4 564 'embeddable' => 'RulesRuleSet',
danielebarchiesi@4 565 'extenders' => array(
danielebarchiesi@4 566 'RulesPluginUIInterface' => array(
danielebarchiesi@4 567 'class' => 'RulesRuleUI',
danielebarchiesi@4 568 ),
danielebarchiesi@4 569 ),
danielebarchiesi@4 570 'import keys' => array('DO', 'IF'),
danielebarchiesi@4 571 ),
danielebarchiesi@4 572 );
danielebarchiesi@4 573 }
danielebarchiesi@4 574
danielebarchiesi@4 575 /**
danielebarchiesi@4 576 * Declare provided rules input evaluators.
danielebarchiesi@4 577 *
danielebarchiesi@4 578 * The hook implementation should be placed into the file MODULENAME.rules.inc,
danielebarchiesi@4 579 * which gets automatically included when the hook is invoked.
danielebarchiesi@4 580 * For implementing an input evaluator a class has to be provided which
danielebarchiesi@4 581 * extends the abstract RulesDataInputEvaluator class. Therefore the abstract
danielebarchiesi@4 582 * methods prepare() and evaluate() have to be implemented, as well as access()
danielebarchiesi@4 583 * and help() could be overridden in order to control access permissions or to
danielebarchiesi@4 584 * provide some usage help.
danielebarchiesi@4 585 *
danielebarchiesi@4 586 * @return
danielebarchiesi@4 587 * An array of information about the module's provided input evaluators. The
danielebarchiesi@4 588 * array contains a sub-array for each evaluator, with the evaluator name as
danielebarchiesi@4 589 * the key. The name may only contain lower case alpha-numeric characters and
danielebarchiesi@4 590 * underscores and should be prefixed with the providing module name. Possible
danielebarchiesi@4 591 * attributes for each sub-array are:
danielebarchiesi@4 592 * - class: The implementation class, which has to extend the
danielebarchiesi@4 593 * RulesDataInputEvaluator class. Required.
danielebarchiesi@4 594 * - weight: A weight for controlling the evaluation order of multiple
danielebarchiesi@4 595 * evaluators. Required.
danielebarchiesi@4 596 * - type: Optionally, the data types for which the input evaluator should be
danielebarchiesi@4 597 * used. Defaults to 'text'. Multiple data types may be specified using an
danielebarchiesi@4 598 * array.
danielebarchiesi@4 599 *
danielebarchiesi@4 600 * @see class RulesDataInputEvaluator
danielebarchiesi@4 601 * @see hook_rules_evaluator_info_alter()
danielebarchiesi@4 602 */
danielebarchiesi@4 603 function hook_rules_evaluator_info() {
danielebarchiesi@4 604 return array(
danielebarchiesi@4 605 'token' => array(
danielebarchiesi@4 606 'class' => 'RulesTokenEvaluator',
danielebarchiesi@4 607 'type' => array('text', 'uri'),
danielebarchiesi@4 608 'weight' => 0,
danielebarchiesi@4 609 ),
danielebarchiesi@4 610 );
danielebarchiesi@4 611 }
danielebarchiesi@4 612
danielebarchiesi@4 613 /**
danielebarchiesi@4 614 * Declare provided rules data processors.
danielebarchiesi@4 615 *
danielebarchiesi@4 616 * The hook implementation should be placed into the file MODULENAME.rules.inc,
danielebarchiesi@4 617 * which gets automatically included when the hook is invoked.
danielebarchiesi@4 618 * For implementing a data processors a class has to be provided which
danielebarchiesi@4 619 * extends the abstract RulesDataProcessor class. Therefore the abstract
danielebarchiesi@4 620 * method process() has to be implemented, but also the methods form() and
danielebarchiesi@4 621 * access() could be overridden in order to provide a configuration form or
danielebarchiesi@4 622 * to control access permissions.
danielebarchiesi@4 623 *
danielebarchiesi@4 624 * @return
danielebarchiesi@4 625 * An array of information about the module's provided data processors. The
danielebarchiesi@4 626 * array contains a sub-array for each processor, with the processor name as
danielebarchiesi@4 627 * the key. The name may only contain lower case alpha-numeric characters and
danielebarchiesi@4 628 * underscores and should be prefixed with the providing module name, whereas
danielebarchiesi@4 629 * 'select' is reserved as well.
danielebarchiesi@4 630 * Possible attributes for each sub-array are:
danielebarchiesi@4 631 * - class: The implementation class, which has to extend the
danielebarchiesi@4 632 * RulesDataProcessor class. Required.
danielebarchiesi@4 633 * - weight: A weight for controlling the processing order of multiple data
danielebarchiesi@4 634 * processors. Required.
danielebarchiesi@4 635 * - type: Optionally, the data types for which the data processor should be
danielebarchiesi@4 636 * used. Defaults to 'text'. Multiple data types may be specified using an
danielebarchiesi@4 637 * array.
danielebarchiesi@4 638 *
danielebarchiesi@4 639 * @see class RulesDataProcessor
danielebarchiesi@4 640 * @see hook_rules_data_processor_info_alter()
danielebarchiesi@4 641 */
danielebarchiesi@4 642 function hook_rules_data_processor_info() {
danielebarchiesi@4 643 return array(
danielebarchiesi@4 644 'date_offset' => array(
danielebarchiesi@4 645 'class' => 'RulesDateOffsetProcessor',
danielebarchiesi@4 646 'type' => 'date',
danielebarchiesi@4 647 'weight' => -2,
danielebarchiesi@4 648 ),
danielebarchiesi@4 649 );
danielebarchiesi@4 650 }
danielebarchiesi@4 651
danielebarchiesi@4 652 /**
danielebarchiesi@4 653 * Alter rules compatible actions.
danielebarchiesi@4 654 *
danielebarchiesi@4 655 * The implementation should be placed into the file MODULENAME.rules.inc, which
danielebarchiesi@4 656 * gets automatically included when the hook is invoked.
danielebarchiesi@4 657 *
danielebarchiesi@4 658 * @param $actions
danielebarchiesi@4 659 * The items of all modules as returned from hook_rules_action_info().
danielebarchiesi@4 660 *
danielebarchiesi@4 661 * @see hook_rules_action_info().
danielebarchiesi@4 662 */
danielebarchiesi@4 663 function hook_rules_action_info_alter(&$actions) {
danielebarchiesi@4 664 // The rules action is more powerful, so hide the core action
danielebarchiesi@4 665 unset($actions['rules_core_node_assign_owner_action']);
danielebarchiesi@4 666 // We prefer handling saving by rules - not by the user.
danielebarchiesi@4 667 unset($actions['rules_core_node_save_action']);
danielebarchiesi@4 668 }
danielebarchiesi@4 669
danielebarchiesi@4 670 /**
danielebarchiesi@4 671 * Alter rules conditions.
danielebarchiesi@4 672 *
danielebarchiesi@4 673 * The implementation should be placed into the file MODULENAME.rules.inc, which
danielebarchiesi@4 674 * gets automatically included when the hook is invoked.
danielebarchiesi@4 675 *
danielebarchiesi@4 676 * @param $conditions
danielebarchiesi@4 677 * The items of all modules as returned from hook_rules_condition_info().
danielebarchiesi@4 678 *
danielebarchiesi@4 679 * @see hook_rules_condition_info()
danielebarchiesi@4 680 */
danielebarchiesi@4 681 function hook_rules_condition_info_alter(&$conditions) {
danielebarchiesi@4 682 // Change conditions.
danielebarchiesi@4 683 }
danielebarchiesi@4 684
danielebarchiesi@4 685 /**
danielebarchiesi@4 686 * Alter rules events.
danielebarchiesi@4 687 *
danielebarchiesi@4 688 * The implementation should be placed into the file MODULENAME.rules.inc, which
danielebarchiesi@4 689 * gets automatically included when the hook is invoked.
danielebarchiesi@4 690 *
danielebarchiesi@4 691 * @param $events
danielebarchiesi@4 692 * The items of all modules as returned from hook_rules_event_info().
danielebarchiesi@4 693 *
danielebarchiesi@4 694 * @see hook_rules_event_info().
danielebarchiesi@4 695 */
danielebarchiesi@4 696 function hook_rules_event_info_alter(&$events) {
danielebarchiesi@4 697 // Change events.
danielebarchiesi@4 698 }
danielebarchiesi@4 699
danielebarchiesi@4 700 /**
danielebarchiesi@4 701 * Alter rules data types.
danielebarchiesi@4 702 *
danielebarchiesi@4 703 * The implementation should be placed into the file MODULENAME.rules.inc, which
danielebarchiesi@4 704 * gets automatically included when the hook is invoked.
danielebarchiesi@4 705 *
danielebarchiesi@4 706 * @param $data_info
danielebarchiesi@4 707 * The items of all modules as returned from hook_rules_data_info().
danielebarchiesi@4 708 *
danielebarchiesi@4 709 * @see hook_rules_data_info()
danielebarchiesi@4 710 */
danielebarchiesi@4 711 function hook_rules_data_info_alter(&$data_info) {
danielebarchiesi@4 712 // Change data types.
danielebarchiesi@4 713 }
danielebarchiesi@4 714
danielebarchiesi@4 715 /**
danielebarchiesi@4 716 * Alter rules plugin info.
danielebarchiesi@4 717 *
danielebarchiesi@4 718 * The implementation should be placed into the file MODULENAME.rules.inc, which
danielebarchiesi@4 719 * gets automatically included when the hook is invoked.
danielebarchiesi@4 720 *
danielebarchiesi@4 721 * @param $plugin_info
danielebarchiesi@4 722 * The items of all modules as returned from hook_rules_plugin_info().
danielebarchiesi@4 723 *
danielebarchiesi@4 724 * @see hook_rules_plugin_info()
danielebarchiesi@4 725 */
danielebarchiesi@4 726 function hook_rules_plugin_info_alter(&$plugin_info) {
danielebarchiesi@4 727 // Change plugin info.
danielebarchiesi@4 728 }
danielebarchiesi@4 729
danielebarchiesi@4 730 /**
danielebarchiesi@4 731 * Alter rules input evaluator info.
danielebarchiesi@4 732 *
danielebarchiesi@4 733 * The implementation should be placed into the file MODULENAME.rules.inc, which
danielebarchiesi@4 734 * gets automatically included when the hook is invoked.
danielebarchiesi@4 735 *
danielebarchiesi@4 736 * @param $evaluator_info
danielebarchiesi@4 737 * The items of all modules as returned from hook_rules_evaluator_info().
danielebarchiesi@4 738 *
danielebarchiesi@4 739 * @see hook_rules_evaluator_info()
danielebarchiesi@4 740 */
danielebarchiesi@4 741 function hook_rules_evaluator_info_alter(&$evaluator_info) {
danielebarchiesi@4 742 // Change evaluator info.
danielebarchiesi@4 743 }
danielebarchiesi@4 744
danielebarchiesi@4 745 /**
danielebarchiesi@4 746 * Alter rules data_processor info.
danielebarchiesi@4 747 *
danielebarchiesi@4 748 * The implementation should be placed into the file MODULENAME.rules.inc, which
danielebarchiesi@4 749 * gets automatically included when the hook is invoked.
danielebarchiesi@4 750 *
danielebarchiesi@4 751 * @param $processor_info
danielebarchiesi@4 752 * The items of all modules as returned from hook_rules_data_processor_info().
danielebarchiesi@4 753 *
danielebarchiesi@4 754 * @see hook_rules_data_processor_info()
danielebarchiesi@4 755 */
danielebarchiesi@4 756 function hook_rules_data_processor_info_alter(&$processor_info) {
danielebarchiesi@4 757 // Change processor info.
danielebarchiesi@4 758 }
danielebarchiesi@4 759
danielebarchiesi@4 760 /**
danielebarchiesi@4 761 * Act on rules configuration being loaded from the database.
danielebarchiesi@4 762 *
danielebarchiesi@4 763 * This hook is invoked during rules configuration loading, which is handled
danielebarchiesi@4 764 * by entity_load(), via classes RulesEntityController and EntityCRUDController.
danielebarchiesi@4 765 *
danielebarchiesi@4 766 * @param $configs
danielebarchiesi@4 767 * An array of rules configurations being loaded, keyed by id.
danielebarchiesi@4 768 */
danielebarchiesi@4 769 function hook_rules_config_load($configs) {
danielebarchiesi@4 770 $result = db_query('SELECT id, foo FROM {mytable} WHERE id IN(:ids)', array(':ids' => array_keys($configs)));
danielebarchiesi@4 771 foreach ($result as $record) {
danielebarchiesi@4 772 $configs[$record->id]->foo = $record->foo;
danielebarchiesi@4 773 }
danielebarchiesi@4 774 }
danielebarchiesi@4 775
danielebarchiesi@4 776 /**
danielebarchiesi@4 777 * Respond to creation of a new rules configuration.
danielebarchiesi@4 778 *
danielebarchiesi@4 779 * This hook is invoked after the rules configuration is inserted into the
danielebarchiesi@4 780 * the database.
danielebarchiesi@4 781 *
danielebarchiesi@4 782 * @param RulesPlugin $config
danielebarchiesi@4 783 * The rules configuration that is being created.
danielebarchiesi@4 784 */
danielebarchiesi@4 785 function hook_rules_config_insert($config) {
danielebarchiesi@4 786 db_insert('mytable')
danielebarchiesi@4 787 ->fields(array(
danielebarchiesi@4 788 'nid' => $config->id,
danielebarchiesi@4 789 'plugin' => $config->plugin,
danielebarchiesi@4 790 ))
danielebarchiesi@4 791 ->execute();
danielebarchiesi@4 792 }
danielebarchiesi@4 793
danielebarchiesi@4 794 /**
danielebarchiesi@4 795 * Act on a rules configuration being inserted or updated.
danielebarchiesi@4 796 *
danielebarchiesi@4 797 * This hook is invoked before the rules configuration is saved to the
danielebarchiesi@4 798 * database.
danielebarchiesi@4 799 *
danielebarchiesi@4 800 * @param RulesPlugin $config
danielebarchiesi@4 801 * The rules configuration that is being inserted or updated.
danielebarchiesi@4 802 */
danielebarchiesi@4 803 function hook_rules_config_presave($config) {
danielebarchiesi@4 804 if ($config->id && $config->owner == 'your_module') {
danielebarchiesi@4 805 // Add custom condition.
danielebarchiesi@4 806 $config->conditon(/* Your condition */);
danielebarchiesi@4 807 }
danielebarchiesi@4 808 }
danielebarchiesi@4 809
danielebarchiesi@4 810 /**
danielebarchiesi@4 811 * Respond to updates to a rules configuration.
danielebarchiesi@4 812 *
danielebarchiesi@4 813 * This hook is invoked after the configuration has been updated in the
danielebarchiesi@4 814 * database.
danielebarchiesi@4 815 *
danielebarchiesi@4 816 * @param RulesPlugin $config
danielebarchiesi@4 817 * The rules configuration that is being updated.
danielebarchiesi@4 818 */
danielebarchiesi@4 819 function hook_rules_config_update($config) {
danielebarchiesi@4 820 db_update('mytable')
danielebarchiesi@4 821 ->fields(array('plugin' => $config->plugin))
danielebarchiesi@4 822 ->condition('id', $config->id)
danielebarchiesi@4 823 ->execute();
danielebarchiesi@4 824 }
danielebarchiesi@4 825
danielebarchiesi@4 826 /**
danielebarchiesi@4 827 * Respond to rules configuration deletion.
danielebarchiesi@4 828 *
danielebarchiesi@4 829 * This hook is invoked after the configuration has been removed from the
danielebarchiesi@4 830 * database.
danielebarchiesi@4 831 *
danielebarchiesi@4 832 * @param RulesPlugin $config
danielebarchiesi@4 833 * The rules configuration that is being deleted.
danielebarchiesi@4 834 */
danielebarchiesi@4 835 function hook_rules_config_delete($config) {
danielebarchiesi@4 836 db_delete('mytable')
danielebarchiesi@4 837 ->condition('id', $config->id)
danielebarchiesi@4 838 ->execute();
danielebarchiesi@4 839 }
danielebarchiesi@4 840
danielebarchiesi@4 841 /**
danielebarchiesi@4 842 * Respond to rules configuration execution.
danielebarchiesi@4 843 *
danielebarchiesi@4 844 * This hook is invoked right before the rules configuration is executed.
danielebarchiesi@4 845 *
danielebarchiesi@4 846 * @param RulesPlugin $config
danielebarchiesi@4 847 * The rules configuration that is being executed.
danielebarchiesi@4 848 */
danielebarchiesi@4 849 function hook_rules_config_execute($config) {
danielebarchiesi@4 850
danielebarchiesi@4 851 }
danielebarchiesi@4 852
danielebarchiesi@4 853 /**
danielebarchiesi@4 854 * Define default rules configurations.
danielebarchiesi@4 855 *
danielebarchiesi@4 856 * This hook is invoked when rules configurations are loaded. The implementation
danielebarchiesi@4 857 * should be placed into the file MODULENAME.rules_defaults.inc, which gets
danielebarchiesi@4 858 * automatically included when the hook is invoked.
danielebarchiesi@4 859 *
danielebarchiesi@4 860 * @return
danielebarchiesi@4 861 * An array of rules configurations with the configuration names as keys.
danielebarchiesi@4 862 *
danielebarchiesi@4 863 * @see hook_default_rules_configuration_alter()
danielebarchiesi@4 864 * @see hook_rules_config_defaults_rebuild()
danielebarchiesi@4 865 */
danielebarchiesi@4 866 function hook_default_rules_configuration() {
danielebarchiesi@4 867 $rule = rules_reaction_rule();
danielebarchiesi@4 868 $rule->label = 'example default rule';
danielebarchiesi@4 869 $rule->active = FALSE;
danielebarchiesi@4 870 $rule->event('node_update')
danielebarchiesi@4 871 ->condition(rules_condition('data_is', array('data:select' => 'node:status', 'value' => TRUE))->negate())
danielebarchiesi@4 872 ->condition('data_is', array('data:select' => 'node:type', 'value' => 'page'))
danielebarchiesi@4 873 ->action('drupal_message', array('message' => 'A node has been updated.'));
danielebarchiesi@4 874
danielebarchiesi@4 875 $configs['rules_test_default_1'] = $rule;
danielebarchiesi@4 876 return $configs;
danielebarchiesi@4 877 }
danielebarchiesi@4 878
danielebarchiesi@4 879 /**
danielebarchiesi@4 880 * Alter default rules configurations.
danielebarchiesi@4 881 *
danielebarchiesi@4 882 * The implementation should be placed into the file
danielebarchiesi@4 883 * MODULENAME.rules_defaults.inc, which gets automatically included when the
danielebarchiesi@4 884 * hook is invoked.
danielebarchiesi@4 885 *
danielebarchiesi@4 886 * @param $configs
danielebarchiesi@4 887 * The default configurations of all modules as returned from
danielebarchiesi@4 888 * hook_default_rules_configuration().
danielebarchiesi@4 889 *
danielebarchiesi@4 890 * @see hook_default_rules_configuration()
danielebarchiesi@4 891 */
danielebarchiesi@4 892 function hook_default_rules_configuration_alter(&$configs) {
danielebarchiesi@4 893 // Add custom condition.
danielebarchiesi@4 894 $configs['foo']->condition('bar');
danielebarchiesi@4 895 }
danielebarchiesi@4 896
danielebarchiesi@4 897 /**
danielebarchiesi@4 898 * Act after rebuilding default configurations.
danielebarchiesi@4 899 *
danielebarchiesi@4 900 * This hook is invoked by the entity module after default rules configurations
danielebarchiesi@4 901 * have been rebuilt; i.e. defaults have been saved to the database.
danielebarchiesi@4 902 *
danielebarchiesi@4 903 * @param $rules_configs
danielebarchiesi@4 904 * The array of default rules configurations which have been inserted or
danielebarchiesi@4 905 * updated, keyed by name.
danielebarchiesi@4 906 * @param $originals
danielebarchiesi@4 907 * An array of original rules configurations keyed by name; i.e. the rules
danielebarchiesi@4 908 * configurations before the current defaults have been applied. For inserted
danielebarchiesi@4 909 * rules configurations no original is available.
danielebarchiesi@4 910 *
danielebarchiesi@4 911 * @see hook_default_rules_configuration()
danielebarchiesi@4 912 * @see entity_defaults_rebuild()
danielebarchiesi@4 913 */
danielebarchiesi@4 914 function hook_rules_config_defaults_rebuild($rules_configs, $originals) {
danielebarchiesi@4 915 // Once all defaults have been rebuilt, update all i18n strings at once. That
danielebarchiesi@4 916 // way we build the rules cache once the rebuild is complete and avoid
danielebarchiesi@4 917 // rebuilding caches for each updated rule.
danielebarchiesi@4 918 foreach ($rules_configs as $name => $rule_config) {
danielebarchiesi@4 919 if (empty($originals[$name])) {
danielebarchiesi@4 920 rules_i18n_rules_config_insert($rule_config);
danielebarchiesi@4 921 }
danielebarchiesi@4 922 else {
danielebarchiesi@4 923 rules_i18n_rules_config_update($rule_config, $originals[$name]);
danielebarchiesi@4 924 }
danielebarchiesi@4 925 }
danielebarchiesi@4 926 }
danielebarchiesi@4 927
danielebarchiesi@4 928 /**
danielebarchiesi@4 929 * Alter rules components before execution.
danielebarchiesi@4 930 *
danielebarchiesi@4 931 * This hooks allows altering rules components before they are cached for later
danielebarchiesi@4 932 * re-use. Use this hook only for altering the component in order to prepare
danielebarchiesi@4 933 * re-use through rules_invoke_component() or the provided condition/action.
danielebarchiesi@4 934 * Note that this hook is only invoked for any components cached for execution,
danielebarchiesi@4 935 * but not for components that are programmatically created and executed on the
danielebarchiesi@4 936 * fly (without saving them).
danielebarchiesi@4 937 *
danielebarchiesi@4 938 * @param $plugin
danielebarchiesi@4 939 * The name of the component plugin.
danielebarchiesi@4 940 * @param $component
danielebarchiesi@4 941 * The component that is to be cached.
danielebarchiesi@4 942 *
danielebarchiesi@4 943 * @see rules_invoke_component()
danielebarchiesi@4 944 */
danielebarchiesi@4 945 function hook_rules_component_alter($plugin, RulesPlugin $component) {
danielebarchiesi@4 946
danielebarchiesi@4 947 }
danielebarchiesi@4 948
danielebarchiesi@4 949 /**
danielebarchiesi@4 950 * Alters event sets.
danielebarchiesi@4 951 *
danielebarchiesi@4 952 * This hooks allows altering rules event sets, which contain all rules that are
danielebarchiesi@4 953 * triggered upon a specific event. Rules internally caches all rules associated
danielebarchiesi@4 954 * to an event in an event set, which is cached for fast evaluation. This hook
danielebarchiesi@4 955 * is invoked just before any event set is cached, thus it allows altering of
danielebarchiesi@4 956 * the to be executed rules without the changes to appear in the UI, e.g. to add
danielebarchiesi@4 957 * a further condition to some rules.
danielebarchiesi@4 958 *
danielebarchiesi@4 959 * @param $event_name
danielebarchiesi@4 960 * The name of the event.
danielebarchiesi@4 961 * @param $event_set
danielebarchiesi@4 962 * The event set that is to be cached.
danielebarchiesi@4 963 *
danielebarchiesi@4 964 * @see rules_invoke_event()
danielebarchiesi@4 965 */
danielebarchiesi@4 966 function hook_rules_event_set_alter($event_name, RulesEventSet $event_set) {
danielebarchiesi@4 967
danielebarchiesi@4 968 }
danielebarchiesi@4 969
danielebarchiesi@4 970 /**
danielebarchiesi@4 971 * D6 to D7 upgrade procedure hook for mapping action or condition names.
danielebarchiesi@4 972 *
danielebarchiesi@4 973 * If for a module the action or condition name changed since Drupal 6, this
danielebarchiesi@4 974 * "hook" can be implemented in order to map to the new name of the action or
danielebarchiesi@4 975 * condition.
danielebarchiesi@4 976 *
danielebarchiesi@4 977 * This is no real hook, but a callback that is invoked for each Drupal 6
danielebarchiesi@4 978 * action or condition that is to be upgraded to Drupal 7. E.g. the function
danielebarchiesi@4 979 * name called for the action "rules_action_set_node_title" would be
danielebarchiesi@4 980 * "rules_action_set_node_title_upgrade_map_name".
danielebarchiesi@4 981 *
danielebarchiesi@4 982 * @param $element
danielebarchiesi@4 983 * The element array of a configured condition or action which is to be
danielebarchiesi@4 984 * upgraded.
danielebarchiesi@4 985 * @return
danielebarchiesi@4 986 * The name of the action or condition which should be used.
danielebarchiesi@4 987 */
danielebarchiesi@4 988 function hook_rules_action_base_upgrade_map_name($element) {
danielebarchiesi@4 989 return 'data_set';
danielebarchiesi@4 990 }
danielebarchiesi@4 991
danielebarchiesi@4 992 /**
danielebarchiesi@4 993 * D6 to D7 upgrade procedure hook for mapping action or condition configuration.
danielebarchiesi@4 994 *
danielebarchiesi@4 995 * During upgrading Drupal 6 rule configurations to Drupal 7 Rules is taking
danielebarchiesi@4 996 * care of upgrading the configuration of all known parameters, which only works
danielebarchiesi@4 997 * if the parameter name has not changed.
danielebarchiesi@4 998 * If something changed, this callback can be used to properly apply the
danielebarchiesi@4 999 * configruation of the Drupal 6 action ($element) to the Drupal 7 version
danielebarchiesi@4 1000 * ($target).
danielebarchiesi@4 1001 *
danielebarchiesi@4 1002 * This is no real hook, but a callback that is invoked for each Drupal 6
danielebarchiesi@4 1003 * action or condition that is to be upgraded to Drupal 7. E.g. the function
danielebarchiesi@4 1004 * name called for the action "rules_action_set_node_title" would be
danielebarchiesi@4 1005 * "rules_action_set_node_title_upgrade".
danielebarchiesi@4 1006 *
danielebarchiesi@4 1007 * @param $element
danielebarchiesi@4 1008 * The element array of a configured condition or action which is to be
danielebarchiesi@4 1009 * upgraded.
danielebarchiesi@4 1010 * @param $target
danielebarchiesi@4 1011 * The Drupal 7 version of the configured element.
danielebarchiesi@4 1012 *
danielebarchiesi@4 1013 * @see hook_rules_element_upgrade_alter()
danielebarchiesi@4 1014 */
danielebarchiesi@4 1015 function hook_rules_action_base_upgrade($element, RulesPlugin $target) {
danielebarchiesi@4 1016 $target->settings['data:select'] = $element['#settings']['#argument map']['node'] . ':title';
danielebarchiesi@4 1017 $target->settings['value'] = $element['#settings']['title'];
danielebarchiesi@4 1018 }
danielebarchiesi@4 1019
danielebarchiesi@4 1020 /**
danielebarchiesi@4 1021 * D6 to D7 upgrade procedure hook for mapping action or condition configuration.
danielebarchiesi@4 1022 *
danielebarchiesi@4 1023 * A alter hook that is called after the action/condition specific callback for
danielebarchiesi@4 1024 * each element of a configuration that is upgraded.
danielebarchiesi@4 1025 *
danielebarchiesi@4 1026 * @param $element
danielebarchiesi@4 1027 * The element array of a configured condition or action which is to be
danielebarchiesi@4 1028 * upgraded.
danielebarchiesi@4 1029 * @param $target
danielebarchiesi@4 1030 * The Drupal 7 version of the configured element.
danielebarchiesi@4 1031 *
danielebarchiesi@4 1032 * @see hook_rules_action_base_upgrade()
danielebarchiesi@4 1033 */
danielebarchiesi@4 1034 function hook_rules_element_upgrade_alter($element, $target) {
danielebarchiesi@4 1035
danielebarchiesi@4 1036 }
danielebarchiesi@4 1037
danielebarchiesi@4 1038 /**
danielebarchiesi@4 1039 * Allows modules to alter or to extend the provided Rules UI.
danielebarchiesi@4 1040 *
danielebarchiesi@4 1041 * Use this hook over the regular hook_menu_alter() as the Rules UI is re-used
danielebarchiesi@4 1042 * and embedded by modules. See rules_ui().
danielebarchiesi@4 1043 *
danielebarchiesi@4 1044 * @param $items
danielebarchiesi@4 1045 * The menu items to alter.
danielebarchiesi@4 1046 * @param $base_path
danielebarchiesi@4 1047 * The base path of the Rules UI.
danielebarchiesi@4 1048 * @param $base_count
danielebarchiesi@4 1049 * The count of the directories contained in the base path.
danielebarchiesi@4 1050 */
danielebarchiesi@4 1051 function hook_rules_ui_menu_alter(&$items, $base_path, $base_count) {
danielebarchiesi@4 1052 $items[$base_path . '/manage/%rules_config/schedule'] = array(
danielebarchiesi@4 1053 'title callback' => 'rules_get_title',
danielebarchiesi@4 1054 'title arguments' => array('Schedule !plugin "!label"', $base_count + 1),
danielebarchiesi@4 1055 'page callback' => 'drupal_get_form',
danielebarchiesi@4 1056 'page arguments' => array('rules_scheduler_schedule_form', $base_count + 1, $base_path),
danielebarchiesi@4 1057 'access callback' => 'rules_config_access',
danielebarchiesi@4 1058 'access arguments' => array('update', $base_count + 1),
danielebarchiesi@4 1059 'file' => 'rules_scheduler.admin.inc',
danielebarchiesi@4 1060 'file path' => drupal_get_path('module', 'rules_scheduler'),
danielebarchiesi@4 1061 );
danielebarchiesi@4 1062 }
danielebarchiesi@4 1063
danielebarchiesi@4 1064 /**
danielebarchiesi@4 1065 * Control access to Rules configurations.
danielebarchiesi@4 1066 *
danielebarchiesi@4 1067 * Modules may implement this hook if they want to have a say in whether or not
danielebarchiesi@4 1068 * a given user has access to perform a given operation on a Rules
danielebarchiesi@4 1069 * configuration.
danielebarchiesi@4 1070 *
danielebarchiesi@4 1071 * @param $op
danielebarchiesi@4 1072 * The operation being performed. One of 'view', 'create', 'update' or
danielebarchiesi@4 1073 * 'delete'.
danielebarchiesi@4 1074 * @param $rules_config
danielebarchiesi@4 1075 * (optional) A Rules configuration to check access for. If nothing is given,
danielebarchiesi@4 1076 * access for all Rules configurations is determined.
danielebarchiesi@4 1077 * @param $account
danielebarchiesi@4 1078 * (optional) The user to check for. If no account is passed, access is
danielebarchiesi@4 1079 * determined for the current user.
danielebarchiesi@4 1080 * @return boolean
danielebarchiesi@4 1081 * Return TRUE to grant access, FALSE to explicitly deny access. Return NULL
danielebarchiesi@4 1082 * or nothing to not affect the operation.
danielebarchiesi@4 1083 * Access is granted as soon as a module grants access and no one denies
danielebarchiesi@4 1084 * access. Thus if no module explicitly grants access, access will be denied.
danielebarchiesi@4 1085 *
danielebarchiesi@4 1086 * @see rules_config_access()
danielebarchiesi@4 1087 */
danielebarchiesi@4 1088 function hook_rules_config_access($op, $rules_config = NULL, $account = NULL) {
danielebarchiesi@4 1089 // Instead of returning FALSE return nothing, so others still can grant
danielebarchiesi@4 1090 // access.
danielebarchiesi@4 1091 if (isset($rules_config) && $rules_config->owner == 'mymodule' && user_access('my modules permission')) {
danielebarchiesi@4 1092 return TRUE;
danielebarchiesi@4 1093 }
danielebarchiesi@4 1094 }
danielebarchiesi@4 1095
danielebarchiesi@4 1096 /**
danielebarchiesi@4 1097 * @}
danielebarchiesi@4 1098 */