rules.api.php 39 KB

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