danielebarchiesi@4: as introduced by danielebarchiesi@4: * the entity metadata module, see hook_entity_property_info(). The special danielebarchiesi@4: * keyword '*' can be used when all types should be allowed. Required. danielebarchiesi@4: * - bundles: (optional) An array of bundle names. When the specified type is danielebarchiesi@4: * set to a single entity type, this may be used to restrict the allowed danielebarchiesi@4: * bundles. danielebarchiesi@4: * - description: (optional) If necessary, a further description of the danielebarchiesi@4: * parameter. danielebarchiesi@4: * - options list: (optional) A callback that returns an array of possible danielebarchiesi@4: * values for this parameter. The callback has to return an array as used danielebarchiesi@4: * by hook_options_list(). For an example implementation see danielebarchiesi@4: * rules_data_action_type_options(). danielebarchiesi@4: * - save: (optional) If this is set to TRUE, the parameter will be saved by danielebarchiesi@4: * rules when the rules evaluation ends. This is only supported for savable danielebarchiesi@4: * data types. If the action returns FALSE, saving is skipped. danielebarchiesi@4: * - optional: (optional) May be set to TRUE, when the parameter isn't danielebarchiesi@4: * required. danielebarchiesi@4: * - 'default value': (optional) The value to pass to the action, in case the danielebarchiesi@4: * parameter is optional and there is no specified value. danielebarchiesi@4: * - 'allow null': (optional) Usually Rules will not pass any NULL values as danielebarchiesi@4: * argument, but abort the evaluation if a NULL value is present. If set to danielebarchiesi@4: * TRUE, Rules will not abort and pass the NULL value through. Defaults to danielebarchiesi@4: * FALSE. danielebarchiesi@4: * - restriction: (optional) Restrict how the argument for this parameter may danielebarchiesi@4: * be provided. Supported values are 'selector' and 'input'. danielebarchiesi@4: * - default mode: (optional) Customize the default mode for providing the danielebarchiesi@4: * argument value for a parameter. Supported values are 'selector' and danielebarchiesi@4: * 'input'. The default depends on the required data type. danielebarchiesi@4: * - sanitize: (optional) Allows parameters of type 'text' to demand an danielebarchiesi@4: * already sanitized argument. If enabled, any user specified value won't be danielebarchiesi@4: * sanitized itself, but replacements applied by input evaluators are as danielebarchiesi@4: * well as values retrieved from selected data sources. danielebarchiesi@4: * - translatable: (optional) If set to TRUE, the provided argument value danielebarchiesi@4: * of the parameter is translatable via i18n String translation. This is danielebarchiesi@4: * applicable for textual parameters only, i.e. parameters of type 'text', danielebarchiesi@4: * 'token', 'list' and 'list'. Defaults to FALSE. danielebarchiesi@4: * - ui class: (optional) Allows overriding the UI class, which is used to danielebarchiesi@4: * generate the configuration UI of a parameter. Defaults to the UI class of danielebarchiesi@4: * the specified data type. danielebarchiesi@4: * - cleaning callback: (optional) A callback that input evaluators may use danielebarchiesi@4: * to clean inserted replacements; e.g. this is used by the token evaluator. danielebarchiesi@4: * - wrapped: (optional) Set this to TRUE in case the data should be passed danielebarchiesi@4: * wrapped. This only applies to wrapped data types, e.g. entities. danielebarchiesi@4: * Each 'provides' array may contain the following properties: danielebarchiesi@4: * - label: The label of the variable. Start capitalized. Required. danielebarchiesi@4: * - type: The rules data type of the variable. All types declared in danielebarchiesi@4: * hook_rules_data_info() may be specified. Types may be parametrized e.g. danielebarchiesi@4: * the types node or list are valid. danielebarchiesi@4: * - save: (optional) If this is set to TRUE, the provided variable is saved danielebarchiesi@4: * by rules when the rules evaluation ends. Only possible for savable data danielebarchiesi@4: * types. Defaults to FALSE. danielebarchiesi@4: * danielebarchiesi@4: * The module has to provide an implementation for each action, being a danielebarchiesi@4: * function named as specified in the 'base' key or for the execution callback. danielebarchiesi@4: * All other possible callbacks are optional. danielebarchiesi@4: * Supported action callbacks by rules are defined and documented in the danielebarchiesi@4: * RulesPluginImplInterface. However any module may extend the action plugin danielebarchiesi@4: * based upon a defined interface using hook_rules_plugin_info(). All methods danielebarchiesi@4: * defined in those interfaces can be overridden by the action implementation. danielebarchiesi@4: * The callback implementations for those interfaces may reside in any file danielebarchiesi@4: * specified in hook_rules_file_info(). danielebarchiesi@4: * danielebarchiesi@4: * @see hook_rules_file_info() danielebarchiesi@4: * @see rules_action_execution_callback() danielebarchiesi@4: * @see hook_rules_plugin_info() danielebarchiesi@4: * @see RulesPluginImplInterface danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_action_info() { danielebarchiesi@4: return array( danielebarchiesi@4: 'mail_user' => array( danielebarchiesi@4: 'label' => t('Send a mail to a user'), danielebarchiesi@4: 'parameter' => array( danielebarchiesi@4: 'user' => array('type' => 'user', 'label' => t('Recipient')), danielebarchiesi@4: ), danielebarchiesi@4: 'group' => t('System'), danielebarchiesi@4: 'base' => 'rules_action_mail_user', danielebarchiesi@4: 'callbacks' => array( danielebarchiesi@4: 'validate' => 'rules_action_custom_validation', danielebarchiesi@4: 'help' => 'rules_mail_help', danielebarchiesi@4: ), danielebarchiesi@4: ), danielebarchiesi@4: ); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Define categories for Rules items, e.g. actions, conditions or events. danielebarchiesi@4: * danielebarchiesi@4: * Categories are similar to the previously used 'group' key in e.g. danielebarchiesi@4: * hook_rules_action_info(), but have a machine name and some more optional danielebarchiesi@4: * keys like a weight, or an icon. danielebarchiesi@4: * danielebarchiesi@4: * For best compatibility, modules may keep using the 'group' key for referring danielebarchiesi@4: * to categories. However, if a 'group' key and a 'category' is given the group danielebarchiesi@4: * will be treated as grouping in the given category (e.g. group "paypal" in danielebarchiesi@4: * category "commerce payment"). danielebarchiesi@4: * danielebarchiesi@4: * @return danielebarchiesi@4: * An array of information about the module's provided categories. danielebarchiesi@4: * The array contains a sub-array for each category, with the category name as danielebarchiesi@4: * the key. Names may only contain lowercase alpha-numeric characters danielebarchiesi@4: * and underscores and should be prefixed with the providing module name. danielebarchiesi@4: * Possible attributes for each sub-array are: danielebarchiesi@4: * - label: The label of the category. Start capitalized. Required. danielebarchiesi@4: * - weight: (optional) A weight for sorting the category. Defaults to 0. danielebarchiesi@4: * - equals group: (optional) For BC, categories may be defined that equal danielebarchiesi@4: * a previsouly used 'group'. danielebarchiesi@4: * - icon: (optional) The file path of an icon to use, relative to the module danielebarchiesi@4: * or specified icon path. The icon should be a transparent SVG containing danielebarchiesi@4: * no colors (only #fff). See https://drupal.org/node/2090265 for danielebarchiesi@4: * instructions on how to create a suiting icon. danielebarchiesi@4: * Note that the icon is currently not used by Rules, however other UIs danielebarchiesi@4: * building upon Rules (like fluxkraft) do, and future releases of Rules danielebarchiesi@4: * might do as well. Consequently, the definition of an icon is optional. danielebarchiesi@4: * However, if both an icon font and icon is given, the icon is preferred. danielebarchiesi@4: * - icon path: (optional) The base path for the icon. Defaults to the danielebarchiesi@4: * providing module's directory. danielebarchiesi@4: * - icon font class: (optional) An icon font class referring to a suiting danielebarchiesi@4: * icon. Icon font class names should map to the ones as defined by Font danielebarchiesi@4: * Awesome, while themes might want to choose to provide another icon font. danielebarchiesi@4: * See http://fortawesome.github.io/Font-Awesome/cheatsheet/. danielebarchiesi@4: * - icon background color: (optional) The color used as icon background. danielebarchiesi@4: * Should have a high contrast to white. Defaults to #ddd. danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_category_info() { danielebarchiesi@4: return array( danielebarchiesi@4: 'rules_data' => array( danielebarchiesi@4: 'label' => t('Data'), danielebarchiesi@4: 'equals group' => t('Data'), danielebarchiesi@4: 'weight' => -50, danielebarchiesi@4: ), danielebarchiesi@4: 'fluxtwitter' => array( danielebarchiesi@4: 'label' => t('Twitter'), danielebarchiesi@4: 'icon font class' => 'icon-twitter', danielebarchiesi@4: 'icon font background color' => '#30a9fd', danielebarchiesi@4: ), danielebarchiesi@4: ); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Specify files containing rules integration code. danielebarchiesi@4: * danielebarchiesi@4: * All files specified in that hook will be included when rules looks for danielebarchiesi@4: * existing callbacks for any plugin. Rules remembers which callback is found in danielebarchiesi@4: * which file and automatically includes the right file before it is executing danielebarchiesi@4: * a plugin method callback. The file yourmodule.rules.inc is added by default danielebarchiesi@4: * and need not be specified here. danielebarchiesi@4: * This allows you to add new include files only containing functions serving as danielebarchiesi@4: * plugin method callbacks in any file without having to care about file danielebarchiesi@4: * inclusion. danielebarchiesi@4: * danielebarchiesi@4: * @return danielebarchiesi@4: * An array of file names without the file ending which defaults to '.inc'. danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_file_info() { danielebarchiesi@4: return array('yourmodule.rules-eval'); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Specifies directories for class-based plugin handler discovery. danielebarchiesi@4: * danielebarchiesi@4: * Implementing this hook is not a requirement, it is just one option to load danielebarchiesi@4: * the files containing the classes during discovery - see danielebarchiesi@4: * rules_discover_plugins(). danielebarchiesi@4: * danielebarchiesi@4: * @return string|array danielebarchiesi@4: * A directory relative to the module directory, which holds the files danielebarchiesi@4: * containing rules plugin handlers, or multiple directories keyed by the danielebarchiesi@4: * module the directory is contained in. danielebarchiesi@4: * All files in those directories having a 'php' or 'inc' file extension will danielebarchiesi@4: * be loaded during discovery. Optionally, wildcards ('*') may be used to danielebarchiesi@4: * match multiple directories. danielebarchiesi@4: * danielebarchiesi@4: * @see rules_discover_plugins() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_directory() { danielebarchiesi@4: return 'lib/Drupal/fluxtwitter/Rules/*'; danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * The execution callback for an action. danielebarchiesi@4: * danielebarchiesi@4: * It should be placed in any file included by your module or in a file danielebarchiesi@4: * specified using hook_rules_file_info(). danielebarchiesi@4: * danielebarchiesi@4: * @param danielebarchiesi@4: * The callback gets arguments passed as described as parameter in danielebarchiesi@4: * hook_rules_action_info() as well as an array containing the action's danielebarchiesi@4: * configuration settings. danielebarchiesi@4: * @return danielebarchiesi@4: * The action may return an array containg parameter or provided variables danielebarchiesi@4: * with their names as key. This is used update the value of a parameter or to danielebarchiesi@4: * provdide the value for a provided variable. danielebarchiesi@4: * Apart from that any parameters which have the key 'save' set to TRUE will danielebarchiesi@4: * be remembered to be saved by rules unless the action returns FALSE. danielebarchiesi@4: * Conditions have to return a boolean value in any case. danielebarchiesi@4: * danielebarchiesi@4: * @see hook_rules_action_info() danielebarchiesi@4: * @see hook_rules_file_info() danielebarchiesi@4: */ danielebarchiesi@4: function rules_action_execution_callback($node, $title, $settings) { danielebarchiesi@4: $node->title = $title; danielebarchiesi@4: return array('node' => $node); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Define rules conditions. danielebarchiesi@4: * danielebarchiesi@4: * This hook is required in order to add a new rules condition. It should be danielebarchiesi@4: * placed into the file MODULENAME.rules.inc, which gets automatically included danielebarchiesi@4: * when the hook is invoked. danielebarchiesi@4: * danielebarchiesi@4: * However, as an alternative to implementing this hook, class based plugin danielebarchiesi@4: * handlers may be provided by implementing RulesConditionHandlerInterface. See danielebarchiesi@4: * the interface for details. danielebarchiesi@4: * danielebarchiesi@4: * Adding conditions works exactly the same way as adding actions, with the danielebarchiesi@4: * exception that conditions can't provide variables and cannot save parameters. danielebarchiesi@4: * Thus the 'provides' attribute is not supported. Furthermore the condition danielebarchiesi@4: * implementation callback has to return a boolean value. danielebarchiesi@4: * danielebarchiesi@4: * @see hook_rules_action_info() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_condition_info() { danielebarchiesi@4: return array( danielebarchiesi@4: 'rules_condition_text_compare' => array( danielebarchiesi@4: 'label' => t('Textual comparison'), danielebarchiesi@4: 'parameter' => array( danielebarchiesi@4: 'text1' => array('label' => t('Text 1'), 'type' => 'text'), danielebarchiesi@4: 'text2' => array('label' => t('Text 2'), 'type' => 'text'), danielebarchiesi@4: ), danielebarchiesi@4: 'group' => t('Rules'), danielebarchiesi@4: ), danielebarchiesi@4: ); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Define rules events. danielebarchiesi@4: * danielebarchiesi@4: * This hook is required in order to add a new rules event. It should be danielebarchiesi@4: * placed into the file MODULENAME.rules.inc, which gets automatically included danielebarchiesi@4: * when the hook is invoked. danielebarchiesi@4: * The module has to invoke the event when it occurs using rules_invoke_event(). danielebarchiesi@4: * This function call has to happen outside of MODULENAME.rules.inc, danielebarchiesi@4: * usually it's invoked directly from the providing module but wrapped by a danielebarchiesi@4: * module_exists('rules') check. danielebarchiesi@4: * danielebarchiesi@4: * However, as an alternative to implementing this hook, class based event danielebarchiesi@4: * handlers may be provided by implementing RulesEventHandlerInterface. See danielebarchiesi@4: * the interface for details. danielebarchiesi@4: * danielebarchiesi@4: * @return danielebarchiesi@4: * An array of information about the module's provided rules events. The array danielebarchiesi@4: * contains a sub-array for each event, with the event name as the key. The danielebarchiesi@4: * name may only contain lower case alpha-numeric characters and underscores danielebarchiesi@4: * and should be prefixed with the providing module name. Possible attributes danielebarchiesi@4: * for each sub-array are: danielebarchiesi@4: * - label: The label of the event. Start capitalized. Required. danielebarchiesi@4: * - group: A group for this element, used for grouping the events in the danielebarchiesi@4: * interface. Should start with a capital letter and be translated. danielebarchiesi@4: * Required. danielebarchiesi@4: * - class: (optional) An event handler class implementing the danielebarchiesi@4: * RulesEventHandlerInterface. If none is specified the danielebarchiesi@4: * RulesEventDefaultHandler class will be used. While the default event danielebarchiesi@4: * handler has no settings, custom event handlers may be implemented to danielebarchiesi@4: * to make an event configurable. See RulesEventHandlerInterface. danielebarchiesi@4: * - access callback: (optional) An callback, which has to return whether the danielebarchiesi@4: * currently logged in user is allowed to configure rules for this event. danielebarchiesi@4: * Access should be only granted, if the user at least may access all the danielebarchiesi@4: * variables provided by the event. danielebarchiesi@4: * - help: (optional) A help text for rules reaction on this event. danielebarchiesi@4: * - variables: (optional) An array describing all variables that are danielebarchiesi@4: * available for elements reacting on this event. Each variable has to be danielebarchiesi@4: * described by a sub-array with the possible attributes: danielebarchiesi@4: * - label: The label of the variable. Start capitalized. Required. danielebarchiesi@4: * - type: The rules data type of the variable. All types declared in danielebarchiesi@4: * hook_rules_data_info() or supported by hook_entity_property_info() may danielebarchiesi@4: * be specified. danielebarchiesi@4: * - bundle: (optional) If the type is an entity type, the bundle of the danielebarchiesi@4: * entity. danielebarchiesi@4: * - description: (optional) A description for the variable. danielebarchiesi@4: * - 'options list': (optional) A callback that returns an array of possible danielebarchiesi@4: * values for this variable as specified for entity properties at danielebarchiesi@4: * hook_entity_property_info(). danielebarchiesi@4: * - 'skip save': (optional) If the variable is saved after the event has danielebarchiesi@4: * occurred anyway, set this to TRUE. So rules won't save the variable a danielebarchiesi@4: * second time. Defaults to FALSE. danielebarchiesi@4: * - handler: (optional) A handler to load the actual variable value. This danielebarchiesi@4: * is useful for lazy loading variables. The handler gets all so far danielebarchiesi@4: * available variables passed in the order as defined. Also see danielebarchiesi@4: * http://drupal.org/node/884554. danielebarchiesi@4: * Note that for lazy-loading entities just the entity id may be passed danielebarchiesi@4: * as variable value, so a handler is not necessary in that case. danielebarchiesi@4: * danielebarchiesi@4: * @see rules_invoke_event() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_event_info() { danielebarchiesi@4: $items = array( danielebarchiesi@4: 'node_insert' => array( danielebarchiesi@4: 'label' => t('After saving new content'), danielebarchiesi@4: 'group' => t('Node'), danielebarchiesi@4: 'variables' => rules_events_node_variables(t('created content')), danielebarchiesi@4: ), danielebarchiesi@4: 'node_update' => array( danielebarchiesi@4: 'label' => t('After updating existing content'), danielebarchiesi@4: 'group' => t('Node'), danielebarchiesi@4: 'variables' => rules_events_node_variables(t('updated content'), TRUE), danielebarchiesi@4: ), danielebarchiesi@4: 'node_presave' => array( danielebarchiesi@4: 'label' => t('Content is going to be saved'), danielebarchiesi@4: 'group' => t('Node'), danielebarchiesi@4: 'variables' => rules_events_node_variables(t('saved content'), TRUE), danielebarchiesi@4: ), danielebarchiesi@4: 'node_view' => array( danielebarchiesi@4: 'label' => t('Content is going to be viewed'), danielebarchiesi@4: 'group' => t('Node'), danielebarchiesi@4: 'variables' => rules_events_node_variables(t('viewed content')) + array( danielebarchiesi@4: 'view_mode' => array('type' => 'text', 'label' => t('view mode')), danielebarchiesi@4: ), danielebarchiesi@4: ), danielebarchiesi@4: 'node_delete' => array( danielebarchiesi@4: 'label' => t('After deleting content'), danielebarchiesi@4: 'group' => t('Node'), danielebarchiesi@4: 'variables' => rules_events_node_variables(t('deleted content')), danielebarchiesi@4: ), danielebarchiesi@4: ); danielebarchiesi@4: // Specify that on presave the node is saved anyway. danielebarchiesi@4: $items['node_presave']['variables']['node']['skip save'] = TRUE; danielebarchiesi@4: return $items; danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Define rules data types. danielebarchiesi@4: * danielebarchiesi@4: * This hook is required in order to add a new rules data type. It should be danielebarchiesi@4: * placed into the file MODULENAME.rules.inc, which gets automatically included danielebarchiesi@4: * when the hook is invoked. danielebarchiesi@4: * Rules builds upon the entity metadata module, thus to improve the support of danielebarchiesi@4: * your data in rules, make it an entity if possible and provide metadata about danielebarchiesi@4: * its properties and CRUD functions by integrating with the entity metadata danielebarchiesi@4: * module. danielebarchiesi@4: * For a list of data types defined by rules see rules_rules_core_data_info(). danielebarchiesi@4: * danielebarchiesi@4: * danielebarchiesi@4: * @return danielebarchiesi@4: * An array of information about the module's provided data types. The array danielebarchiesi@4: * contains a sub-array for each data type, with the data type name as the danielebarchiesi@4: * key. The name may only contain lower case alpha-numeric characters and danielebarchiesi@4: * underscores and should be prefixed with the providing module name. Possible danielebarchiesi@4: * attributes for each sub-array are: danielebarchiesi@4: * - label: The label of the data type. Start uncapitalized. Required. danielebarchiesi@4: * - parent: (optional) A parent type may be set to specify a sub-type danielebarchiesi@4: * relationship, which will be only used for checking compatible types. E.g. danielebarchiesi@4: * the 'entity' data type is parent of the 'node' data type, thus a node may danielebarchiesi@4: * be also used for any action needing an 'entity' parameter. Can be set to danielebarchiesi@4: * any known rules data type. danielebarchiesi@4: * - ui class: (optional) Specify a class that is used to generate the danielebarchiesi@4: * configuration UI to configure parameters of this type. The given class danielebarchiesi@4: * must extend RulesDataUI and may implement the danielebarchiesi@4: * RulesDataDirectInputFormInterface in order to allow the direct data input danielebarchiesi@4: * configuration mode. For supporting selecting values from options lists, danielebarchiesi@4: * the UI class may implement RulesDataInputOptionsListInterface also. danielebarchiesi@4: * Defaults to RulesDataUI. danielebarchiesi@4: * - wrap: (optional) If set to TRUE, the data is wrapped internally using danielebarchiesi@4: * wrappers provided by the entity API module. This is required for entities danielebarchiesi@4: * and data structures to support selecting a property via the data selector danielebarchiesi@4: * and for intelligent saving. danielebarchiesi@4: * - is wrapped: (optional) In case the data wrapper is already wrapped when danielebarchiesi@4: * passed to Rules and Rules should not unwrap it when passing the data as danielebarchiesi@4: * argument, e.g. to an action, set this to TRUE. The default FALSE is fine danielebarchiesi@4: * in most cases. danielebarchiesi@4: * - wrapper class: (optional) Allows the specification of a custom wrapper danielebarchiesi@4: * class, which has to inherit from 'EntityMetadataWrapper'. If given Rules danielebarchiesi@4: * makes use of the class for wrapping the data of the given type. However danielebarchiesi@4: * note that if data is already wrapped when it is passed to Rules, the danielebarchiesi@4: * existing wrappers will be kept. danielebarchiesi@4: * For modules implementing identifiable data types being non-entites the danielebarchiesi@4: * class RulesIdentifiableDataWrapper is provided, which can be used as base danielebarchiesi@4: * for a custom wrapper class. See RulesIdentifiableDataWrapper for details. danielebarchiesi@4: * - property info: (optional) May be used for non-entity data structures to danielebarchiesi@4: * provide info about the data properties, such that data selectors via an danielebarchiesi@4: * entity metadata wrapper are supported. Specify an array as expected by danielebarchiesi@4: * the $info parameter of entity_metadata_wrapper(). danielebarchiesi@4: * - creation callback: (optional) If 'property info' is given, an optional danielebarchiesi@4: * callback that makes use of the property info to create a new instance of danielebarchiesi@4: * this data type. Entities should use hook_entity_info() to specify the danielebarchiesi@4: * 'creation callback' instead, as utilized by the entity API module. See danielebarchiesi@4: * rules_action_data_create_array() for an example callback. danielebarchiesi@4: * - property defaults: (optional) May be used for non-entity data structures danielebarchiesi@4: * to to provide property info defaults for the data properties. Specify an danielebarchiesi@4: * array as expected by entity_metadata_wrapper(). danielebarchiesi@4: * - group: (optional) A group for this element, used for grouping the data danielebarchiesi@4: * types in the interface. Should start with a capital letter and be danielebarchiesi@4: * translated. danielebarchiesi@4: * - token type: (optional) The type name as used by the token module. danielebarchiesi@4: * Defaults to the type name as used by rules. Use FALSE to let token ignore danielebarchiesi@4: * this type. danielebarchiesi@4: * - cleaning callback: (optional) A callback that input evaluators may use danielebarchiesi@4: * to clean inserted replacements; e.g. this is used by the token evaluator. danielebarchiesi@4: * danielebarchiesi@4: * @see entity_metadata_wrapper() danielebarchiesi@4: * @see hook_rules_data_info_alter() danielebarchiesi@4: * @see rules_rules_core_data_info() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_data_info() { danielebarchiesi@4: return array( danielebarchiesi@4: 'node' => array( danielebarchiesi@4: 'label' => t('content'), danielebarchiesi@4: 'parent' => 'entity', danielebarchiesi@4: 'group' => t('Node'), danielebarchiesi@4: ), danielebarchiesi@4: // Formatted text as used by in hook_entity_property_info() for text fields. danielebarchiesi@4: 'text_formatted' => array( danielebarchiesi@4: 'label' => t('formatted text'), danielebarchiesi@4: 'ui class' => 'RulesDataUITextFormatted', danielebarchiesi@4: 'wrap' => TRUE, danielebarchiesi@4: 'property info' => entity_property_text_formatted_info(), danielebarchiesi@4: ), danielebarchiesi@4: ); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Defines rules plugins. danielebarchiesi@4: * danielebarchiesi@4: * A rules configuration may consist of elements being instances of any rules danielebarchiesi@4: * plugin. This hook can be used to define new or to extend rules plugins. danielebarchiesi@4: * danielebarchiesi@4: * @return danielebarchiesi@4: * An array of information about the module's provided rules plugins. The danielebarchiesi@4: * array contains a sub-array for each plugin, with the plugin name as the danielebarchiesi@4: * key. The name may only contain lower case alpha-numeric characters, danielebarchiesi@4: * underscores and spaces and should be prefixed with the providing module danielebarchiesi@4: * name. Possible attributes for danielebarchiesi@4: * each sub-array are: danielebarchiesi@4: * - label: A label for the plugin. Start capitalized. Required only for danielebarchiesi@4: * components (see below). danielebarchiesi@4: * - class: The implementation class. Has to extend the RulesPlugin class. danielebarchiesi@4: * - embeddable: A container class in which elements of those plugin may be danielebarchiesi@4: * embedded via the UI or FALSE to disallow embedding it via the UI. This danielebarchiesi@4: * has no implications on the API level though. Common classes that are danielebarchiesi@4: * used here are RulesConditionContainer and RulesActionContainer. danielebarchiesi@4: * - component: If set to TRUE, the rules admin UI will list elements of those danielebarchiesi@4: * plugin in the components UI and allows the creation of new components danielebarchiesi@4: * based upon this plugin. Optional. danielebarchiesi@4: * - extenders: This allows one to specify faces extenders, which may be used danielebarchiesi@4: * to dynamically implement interfaces. Optional. All extenders specified danielebarchiesi@4: * here are setup automatically by rules once the object is created. To danielebarchiesi@4: * specify set this to an array, where the keys are the implemented danielebarchiesi@4: * interfaces pointing to another array with the keys: danielebarchiesi@4: * - class: The class of the extender, implementing the FacesExtender danielebarchiesi@4: * and the specified interface. Either 'class' or 'methods' has to exist. danielebarchiesi@4: * - methods: An array of callbacks that implement the methods of the danielebarchiesi@4: * interface where the method names are the keys and the callback names danielebarchiesi@4: * the values. There has to be a callback for each defined method. danielebarchiesi@4: * - file: An optional array describing the file to include when a method danielebarchiesi@4: * of the interface is invoked. The array entries known are 'type', danielebarchiesi@4: * 'module', and 'name' matching the parameters of module_load_include(). danielebarchiesi@4: * Only 'module' is required as 'type' defaults to 'inc' and 'name' to danielebarchiesi@4: * NULL. danielebarchiesi@4: * - overrides: An optional array, which may be used to specify callbacks to danielebarchiesi@4: * override specific methods. For that the following keys are supported: danielebarchiesi@4: * - methods: As in the extenders array, but you may specify as many methods danielebarchiesi@4: * here as you like. danielebarchiesi@4: * - file: Optionally an array specifying a file to include for a method. danielebarchiesi@4: * For each method appearing in methods a file may be specified by using danielebarchiesi@4: * the method name as key and another array as value, which describes the danielebarchiesi@4: * file to include - looking like the file array supported by 'extenders'. danielebarchiesi@4: * - import keys: (optional) Embeddable plugins may specify an array of import danielebarchiesi@4: * keys, which the plugin make use for exporting. Defaults to the upper danielebarchiesi@4: * case plugin name, thus the key 'OR' in an export triggers the creation danielebarchiesi@4: * of the 'or' plugin. Note that only uppercase values are allowed, as danielebarchiesi@4: * lower case values are treated as action or condition exports. danielebarchiesi@4: * danielebarchiesi@4: * @see class RulesPlugin danielebarchiesi@4: * @see hook_rules_plugin_info_alter() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_plugin_info() { danielebarchiesi@4: return array( danielebarchiesi@4: 'or' => array( danielebarchiesi@4: 'label' => t('Condition set (OR)'), danielebarchiesi@4: 'class' => 'RulesOr', danielebarchiesi@4: 'embeddable' => 'RulesConditionContainer', danielebarchiesi@4: 'component' => TRUE, danielebarchiesi@4: 'extenders' => array( danielebarchiesi@4: 'RulesPluginUIInterface' => array( danielebarchiesi@4: 'class' => 'RulesConditionContainerUI', danielebarchiesi@4: ), danielebarchiesi@4: ), danielebarchiesi@4: ), danielebarchiesi@4: 'rule' => array( danielebarchiesi@4: 'class' => 'Rule', danielebarchiesi@4: 'embeddable' => 'RulesRuleSet', danielebarchiesi@4: 'extenders' => array( danielebarchiesi@4: 'RulesPluginUIInterface' => array( danielebarchiesi@4: 'class' => 'RulesRuleUI', danielebarchiesi@4: ), danielebarchiesi@4: ), danielebarchiesi@4: 'import keys' => array('DO', 'IF'), danielebarchiesi@4: ), danielebarchiesi@4: ); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Declare provided rules input evaluators. danielebarchiesi@4: * danielebarchiesi@4: * The hook implementation should be placed into the file MODULENAME.rules.inc, danielebarchiesi@4: * which gets automatically included when the hook is invoked. danielebarchiesi@4: * For implementing an input evaluator a class has to be provided which danielebarchiesi@4: * extends the abstract RulesDataInputEvaluator class. Therefore the abstract danielebarchiesi@4: * methods prepare() and evaluate() have to be implemented, as well as access() danielebarchiesi@4: * and help() could be overridden in order to control access permissions or to danielebarchiesi@4: * provide some usage help. danielebarchiesi@4: * danielebarchiesi@4: * @return danielebarchiesi@4: * An array of information about the module's provided input evaluators. The danielebarchiesi@4: * array contains a sub-array for each evaluator, with the evaluator name as danielebarchiesi@4: * the key. The name may only contain lower case alpha-numeric characters and danielebarchiesi@4: * underscores and should be prefixed with the providing module name. Possible danielebarchiesi@4: * attributes for each sub-array are: danielebarchiesi@4: * - class: The implementation class, which has to extend the danielebarchiesi@4: * RulesDataInputEvaluator class. Required. danielebarchiesi@4: * - weight: A weight for controlling the evaluation order of multiple danielebarchiesi@4: * evaluators. Required. danielebarchiesi@4: * - type: Optionally, the data types for which the input evaluator should be danielebarchiesi@4: * used. Defaults to 'text'. Multiple data types may be specified using an danielebarchiesi@4: * array. danielebarchiesi@4: * danielebarchiesi@4: * @see class RulesDataInputEvaluator danielebarchiesi@4: * @see hook_rules_evaluator_info_alter() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_evaluator_info() { danielebarchiesi@4: return array( danielebarchiesi@4: 'token' => array( danielebarchiesi@4: 'class' => 'RulesTokenEvaluator', danielebarchiesi@4: 'type' => array('text', 'uri'), danielebarchiesi@4: 'weight' => 0, danielebarchiesi@4: ), danielebarchiesi@4: ); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Declare provided rules data processors. danielebarchiesi@4: * danielebarchiesi@4: * The hook implementation should be placed into the file MODULENAME.rules.inc, danielebarchiesi@4: * which gets automatically included when the hook is invoked. danielebarchiesi@4: * For implementing a data processors a class has to be provided which danielebarchiesi@4: * extends the abstract RulesDataProcessor class. Therefore the abstract danielebarchiesi@4: * method process() has to be implemented, but also the methods form() and danielebarchiesi@4: * access() could be overridden in order to provide a configuration form or danielebarchiesi@4: * to control access permissions. danielebarchiesi@4: * danielebarchiesi@4: * @return danielebarchiesi@4: * An array of information about the module's provided data processors. The danielebarchiesi@4: * array contains a sub-array for each processor, with the processor name as danielebarchiesi@4: * the key. The name may only contain lower case alpha-numeric characters and danielebarchiesi@4: * underscores and should be prefixed with the providing module name, whereas danielebarchiesi@4: * 'select' is reserved as well. danielebarchiesi@4: * Possible attributes for each sub-array are: danielebarchiesi@4: * - class: The implementation class, which has to extend the danielebarchiesi@4: * RulesDataProcessor class. Required. danielebarchiesi@4: * - weight: A weight for controlling the processing order of multiple data danielebarchiesi@4: * processors. Required. danielebarchiesi@4: * - type: Optionally, the data types for which the data processor should be danielebarchiesi@4: * used. Defaults to 'text'. Multiple data types may be specified using an danielebarchiesi@4: * array. danielebarchiesi@4: * danielebarchiesi@4: * @see class RulesDataProcessor danielebarchiesi@4: * @see hook_rules_data_processor_info_alter() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_data_processor_info() { danielebarchiesi@4: return array( danielebarchiesi@4: 'date_offset' => array( danielebarchiesi@4: 'class' => 'RulesDateOffsetProcessor', danielebarchiesi@4: 'type' => 'date', danielebarchiesi@4: 'weight' => -2, danielebarchiesi@4: ), danielebarchiesi@4: ); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Alter rules compatible actions. danielebarchiesi@4: * danielebarchiesi@4: * The implementation should be placed into the file MODULENAME.rules.inc, which danielebarchiesi@4: * gets automatically included when the hook is invoked. danielebarchiesi@4: * danielebarchiesi@4: * @param $actions danielebarchiesi@4: * The items of all modules as returned from hook_rules_action_info(). danielebarchiesi@4: * danielebarchiesi@4: * @see hook_rules_action_info(). danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_action_info_alter(&$actions) { danielebarchiesi@4: // The rules action is more powerful, so hide the core action danielebarchiesi@4: unset($actions['rules_core_node_assign_owner_action']); danielebarchiesi@4: // We prefer handling saving by rules - not by the user. danielebarchiesi@4: unset($actions['rules_core_node_save_action']); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Alter rules conditions. danielebarchiesi@4: * danielebarchiesi@4: * The implementation should be placed into the file MODULENAME.rules.inc, which danielebarchiesi@4: * gets automatically included when the hook is invoked. danielebarchiesi@4: * danielebarchiesi@4: * @param $conditions danielebarchiesi@4: * The items of all modules as returned from hook_rules_condition_info(). danielebarchiesi@4: * danielebarchiesi@4: * @see hook_rules_condition_info() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_condition_info_alter(&$conditions) { danielebarchiesi@4: // Change conditions. danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Alter rules events. danielebarchiesi@4: * danielebarchiesi@4: * The implementation should be placed into the file MODULENAME.rules.inc, which danielebarchiesi@4: * gets automatically included when the hook is invoked. danielebarchiesi@4: * danielebarchiesi@4: * @param $events danielebarchiesi@4: * The items of all modules as returned from hook_rules_event_info(). danielebarchiesi@4: * danielebarchiesi@4: * @see hook_rules_event_info(). danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_event_info_alter(&$events) { danielebarchiesi@4: // Change events. danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Alter rules data types. danielebarchiesi@4: * danielebarchiesi@4: * The implementation should be placed into the file MODULENAME.rules.inc, which danielebarchiesi@4: * gets automatically included when the hook is invoked. danielebarchiesi@4: * danielebarchiesi@4: * @param $data_info danielebarchiesi@4: * The items of all modules as returned from hook_rules_data_info(). danielebarchiesi@4: * danielebarchiesi@4: * @see hook_rules_data_info() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_data_info_alter(&$data_info) { danielebarchiesi@4: // Change data types. danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Alter rules plugin info. danielebarchiesi@4: * danielebarchiesi@4: * The implementation should be placed into the file MODULENAME.rules.inc, which danielebarchiesi@4: * gets automatically included when the hook is invoked. danielebarchiesi@4: * danielebarchiesi@4: * @param $plugin_info danielebarchiesi@4: * The items of all modules as returned from hook_rules_plugin_info(). danielebarchiesi@4: * danielebarchiesi@4: * @see hook_rules_plugin_info() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_plugin_info_alter(&$plugin_info) { danielebarchiesi@4: // Change plugin info. danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Alter rules input evaluator info. danielebarchiesi@4: * danielebarchiesi@4: * The implementation should be placed into the file MODULENAME.rules.inc, which danielebarchiesi@4: * gets automatically included when the hook is invoked. danielebarchiesi@4: * danielebarchiesi@4: * @param $evaluator_info danielebarchiesi@4: * The items of all modules as returned from hook_rules_evaluator_info(). danielebarchiesi@4: * danielebarchiesi@4: * @see hook_rules_evaluator_info() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_evaluator_info_alter(&$evaluator_info) { danielebarchiesi@4: // Change evaluator info. danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Alter rules data_processor info. danielebarchiesi@4: * danielebarchiesi@4: * The implementation should be placed into the file MODULENAME.rules.inc, which danielebarchiesi@4: * gets automatically included when the hook is invoked. danielebarchiesi@4: * danielebarchiesi@4: * @param $processor_info danielebarchiesi@4: * The items of all modules as returned from hook_rules_data_processor_info(). danielebarchiesi@4: * danielebarchiesi@4: * @see hook_rules_data_processor_info() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_data_processor_info_alter(&$processor_info) { danielebarchiesi@4: // Change processor info. danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Act on rules configuration being loaded from the database. danielebarchiesi@4: * danielebarchiesi@4: * This hook is invoked during rules configuration loading, which is handled danielebarchiesi@4: * by entity_load(), via classes RulesEntityController and EntityCRUDController. danielebarchiesi@4: * danielebarchiesi@4: * @param $configs danielebarchiesi@4: * An array of rules configurations being loaded, keyed by id. danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_config_load($configs) { danielebarchiesi@4: $result = db_query('SELECT id, foo FROM {mytable} WHERE id IN(:ids)', array(':ids' => array_keys($configs))); danielebarchiesi@4: foreach ($result as $record) { danielebarchiesi@4: $configs[$record->id]->foo = $record->foo; danielebarchiesi@4: } danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Respond to creation of a new rules configuration. danielebarchiesi@4: * danielebarchiesi@4: * This hook is invoked after the rules configuration is inserted into the danielebarchiesi@4: * the database. danielebarchiesi@4: * danielebarchiesi@4: * @param RulesPlugin $config danielebarchiesi@4: * The rules configuration that is being created. danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_config_insert($config) { danielebarchiesi@4: db_insert('mytable') danielebarchiesi@4: ->fields(array( danielebarchiesi@4: 'nid' => $config->id, danielebarchiesi@4: 'plugin' => $config->plugin, danielebarchiesi@4: )) danielebarchiesi@4: ->execute(); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Act on a rules configuration being inserted or updated. danielebarchiesi@4: * danielebarchiesi@4: * This hook is invoked before the rules configuration is saved to the danielebarchiesi@4: * database. danielebarchiesi@4: * danielebarchiesi@4: * @param RulesPlugin $config danielebarchiesi@4: * The rules configuration that is being inserted or updated. danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_config_presave($config) { danielebarchiesi@4: if ($config->id && $config->owner == 'your_module') { danielebarchiesi@4: // Add custom condition. danielebarchiesi@4: $config->conditon(/* Your condition */); danielebarchiesi@4: } danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Respond to updates to a rules configuration. danielebarchiesi@4: * danielebarchiesi@4: * This hook is invoked after the configuration has been updated in the danielebarchiesi@4: * database. danielebarchiesi@4: * danielebarchiesi@4: * @param RulesPlugin $config danielebarchiesi@4: * The rules configuration that is being updated. danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_config_update($config) { danielebarchiesi@4: db_update('mytable') danielebarchiesi@4: ->fields(array('plugin' => $config->plugin)) danielebarchiesi@4: ->condition('id', $config->id) danielebarchiesi@4: ->execute(); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Respond to rules configuration deletion. danielebarchiesi@4: * danielebarchiesi@4: * This hook is invoked after the configuration has been removed from the danielebarchiesi@4: * database. danielebarchiesi@4: * danielebarchiesi@4: * @param RulesPlugin $config danielebarchiesi@4: * The rules configuration that is being deleted. danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_config_delete($config) { danielebarchiesi@4: db_delete('mytable') danielebarchiesi@4: ->condition('id', $config->id) danielebarchiesi@4: ->execute(); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Respond to rules configuration execution. danielebarchiesi@4: * danielebarchiesi@4: * This hook is invoked right before the rules configuration is executed. danielebarchiesi@4: * danielebarchiesi@4: * @param RulesPlugin $config danielebarchiesi@4: * The rules configuration that is being executed. danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_config_execute($config) { danielebarchiesi@4: danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Define default rules configurations. danielebarchiesi@4: * danielebarchiesi@4: * This hook is invoked when rules configurations are loaded. The implementation danielebarchiesi@4: * should be placed into the file MODULENAME.rules_defaults.inc, which gets danielebarchiesi@4: * automatically included when the hook is invoked. danielebarchiesi@4: * danielebarchiesi@4: * @return danielebarchiesi@4: * An array of rules configurations with the configuration names as keys. danielebarchiesi@4: * danielebarchiesi@4: * @see hook_default_rules_configuration_alter() danielebarchiesi@4: * @see hook_rules_config_defaults_rebuild() danielebarchiesi@4: */ danielebarchiesi@4: function hook_default_rules_configuration() { danielebarchiesi@4: $rule = rules_reaction_rule(); danielebarchiesi@4: $rule->label = 'example default rule'; danielebarchiesi@4: $rule->active = FALSE; danielebarchiesi@4: $rule->event('node_update') danielebarchiesi@4: ->condition(rules_condition('data_is', array('data:select' => 'node:status', 'value' => TRUE))->negate()) danielebarchiesi@4: ->condition('data_is', array('data:select' => 'node:type', 'value' => 'page')) danielebarchiesi@4: ->action('drupal_message', array('message' => 'A node has been updated.')); danielebarchiesi@4: danielebarchiesi@4: $configs['rules_test_default_1'] = $rule; danielebarchiesi@4: return $configs; danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Alter default rules configurations. danielebarchiesi@4: * danielebarchiesi@4: * The implementation should be placed into the file danielebarchiesi@4: * MODULENAME.rules_defaults.inc, which gets automatically included when the danielebarchiesi@4: * hook is invoked. danielebarchiesi@4: * danielebarchiesi@4: * @param $configs danielebarchiesi@4: * The default configurations of all modules as returned from danielebarchiesi@4: * hook_default_rules_configuration(). danielebarchiesi@4: * danielebarchiesi@4: * @see hook_default_rules_configuration() danielebarchiesi@4: */ danielebarchiesi@4: function hook_default_rules_configuration_alter(&$configs) { danielebarchiesi@4: // Add custom condition. danielebarchiesi@4: $configs['foo']->condition('bar'); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Act after rebuilding default configurations. danielebarchiesi@4: * danielebarchiesi@4: * This hook is invoked by the entity module after default rules configurations danielebarchiesi@4: * have been rebuilt; i.e. defaults have been saved to the database. danielebarchiesi@4: * danielebarchiesi@4: * @param $rules_configs danielebarchiesi@4: * The array of default rules configurations which have been inserted or danielebarchiesi@4: * updated, keyed by name. danielebarchiesi@4: * @param $originals danielebarchiesi@4: * An array of original rules configurations keyed by name; i.e. the rules danielebarchiesi@4: * configurations before the current defaults have been applied. For inserted danielebarchiesi@4: * rules configurations no original is available. danielebarchiesi@4: * danielebarchiesi@4: * @see hook_default_rules_configuration() danielebarchiesi@4: * @see entity_defaults_rebuild() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_config_defaults_rebuild($rules_configs, $originals) { danielebarchiesi@4: // Once all defaults have been rebuilt, update all i18n strings at once. That danielebarchiesi@4: // way we build the rules cache once the rebuild is complete and avoid danielebarchiesi@4: // rebuilding caches for each updated rule. danielebarchiesi@4: foreach ($rules_configs as $name => $rule_config) { danielebarchiesi@4: if (empty($originals[$name])) { danielebarchiesi@4: rules_i18n_rules_config_insert($rule_config); danielebarchiesi@4: } danielebarchiesi@4: else { danielebarchiesi@4: rules_i18n_rules_config_update($rule_config, $originals[$name]); danielebarchiesi@4: } danielebarchiesi@4: } danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Alter rules components before execution. danielebarchiesi@4: * danielebarchiesi@4: * This hooks allows altering rules components before they are cached for later danielebarchiesi@4: * re-use. Use this hook only for altering the component in order to prepare danielebarchiesi@4: * re-use through rules_invoke_component() or the provided condition/action. danielebarchiesi@4: * Note that this hook is only invoked for any components cached for execution, danielebarchiesi@4: * but not for components that are programmatically created and executed on the danielebarchiesi@4: * fly (without saving them). danielebarchiesi@4: * danielebarchiesi@4: * @param $plugin danielebarchiesi@4: * The name of the component plugin. danielebarchiesi@4: * @param $component danielebarchiesi@4: * The component that is to be cached. danielebarchiesi@4: * danielebarchiesi@4: * @see rules_invoke_component() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_component_alter($plugin, RulesPlugin $component) { danielebarchiesi@4: danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Alters event sets. danielebarchiesi@4: * danielebarchiesi@4: * This hooks allows altering rules event sets, which contain all rules that are danielebarchiesi@4: * triggered upon a specific event. Rules internally caches all rules associated danielebarchiesi@4: * to an event in an event set, which is cached for fast evaluation. This hook danielebarchiesi@4: * is invoked just before any event set is cached, thus it allows altering of danielebarchiesi@4: * the to be executed rules without the changes to appear in the UI, e.g. to add danielebarchiesi@4: * a further condition to some rules. danielebarchiesi@4: * danielebarchiesi@4: * @param $event_name danielebarchiesi@4: * The name of the event. danielebarchiesi@4: * @param $event_set danielebarchiesi@4: * The event set that is to be cached. danielebarchiesi@4: * danielebarchiesi@4: * @see rules_invoke_event() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_event_set_alter($event_name, RulesEventSet $event_set) { danielebarchiesi@4: danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * D6 to D7 upgrade procedure hook for mapping action or condition names. danielebarchiesi@4: * danielebarchiesi@4: * If for a module the action or condition name changed since Drupal 6, this danielebarchiesi@4: * "hook" can be implemented in order to map to the new name of the action or danielebarchiesi@4: * condition. danielebarchiesi@4: * danielebarchiesi@4: * This is no real hook, but a callback that is invoked for each Drupal 6 danielebarchiesi@4: * action or condition that is to be upgraded to Drupal 7. E.g. the function danielebarchiesi@4: * name called for the action "rules_action_set_node_title" would be danielebarchiesi@4: * "rules_action_set_node_title_upgrade_map_name". danielebarchiesi@4: * danielebarchiesi@4: * @param $element danielebarchiesi@4: * The element array of a configured condition or action which is to be danielebarchiesi@4: * upgraded. danielebarchiesi@4: * @return danielebarchiesi@4: * The name of the action or condition which should be used. danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_action_base_upgrade_map_name($element) { danielebarchiesi@4: return 'data_set'; danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * D6 to D7 upgrade procedure hook for mapping action or condition configuration. danielebarchiesi@4: * danielebarchiesi@4: * During upgrading Drupal 6 rule configurations to Drupal 7 Rules is taking danielebarchiesi@4: * care of upgrading the configuration of all known parameters, which only works danielebarchiesi@4: * if the parameter name has not changed. danielebarchiesi@4: * If something changed, this callback can be used to properly apply the danielebarchiesi@4: * configruation of the Drupal 6 action ($element) to the Drupal 7 version danielebarchiesi@4: * ($target). danielebarchiesi@4: * danielebarchiesi@4: * This is no real hook, but a callback that is invoked for each Drupal 6 danielebarchiesi@4: * action or condition that is to be upgraded to Drupal 7. E.g. the function danielebarchiesi@4: * name called for the action "rules_action_set_node_title" would be danielebarchiesi@4: * "rules_action_set_node_title_upgrade". danielebarchiesi@4: * danielebarchiesi@4: * @param $element danielebarchiesi@4: * The element array of a configured condition or action which is to be danielebarchiesi@4: * upgraded. danielebarchiesi@4: * @param $target danielebarchiesi@4: * The Drupal 7 version of the configured element. danielebarchiesi@4: * danielebarchiesi@4: * @see hook_rules_element_upgrade_alter() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_action_base_upgrade($element, RulesPlugin $target) { danielebarchiesi@4: $target->settings['data:select'] = $element['#settings']['#argument map']['node'] . ':title'; danielebarchiesi@4: $target->settings['value'] = $element['#settings']['title']; danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * D6 to D7 upgrade procedure hook for mapping action or condition configuration. danielebarchiesi@4: * danielebarchiesi@4: * A alter hook that is called after the action/condition specific callback for danielebarchiesi@4: * each element of a configuration that is upgraded. danielebarchiesi@4: * danielebarchiesi@4: * @param $element danielebarchiesi@4: * The element array of a configured condition or action which is to be danielebarchiesi@4: * upgraded. danielebarchiesi@4: * @param $target danielebarchiesi@4: * The Drupal 7 version of the configured element. danielebarchiesi@4: * danielebarchiesi@4: * @see hook_rules_action_base_upgrade() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_element_upgrade_alter($element, $target) { danielebarchiesi@4: danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Allows modules to alter or to extend the provided Rules UI. danielebarchiesi@4: * danielebarchiesi@4: * Use this hook over the regular hook_menu_alter() as the Rules UI is re-used danielebarchiesi@4: * and embedded by modules. See rules_ui(). danielebarchiesi@4: * danielebarchiesi@4: * @param $items danielebarchiesi@4: * The menu items to alter. danielebarchiesi@4: * @param $base_path danielebarchiesi@4: * The base path of the Rules UI. danielebarchiesi@4: * @param $base_count danielebarchiesi@4: * The count of the directories contained in the base path. danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_ui_menu_alter(&$items, $base_path, $base_count) { danielebarchiesi@4: $items[$base_path . '/manage/%rules_config/schedule'] = array( danielebarchiesi@4: 'title callback' => 'rules_get_title', danielebarchiesi@4: 'title arguments' => array('Schedule !plugin "!label"', $base_count + 1), danielebarchiesi@4: 'page callback' => 'drupal_get_form', danielebarchiesi@4: 'page arguments' => array('rules_scheduler_schedule_form', $base_count + 1, $base_path), danielebarchiesi@4: 'access callback' => 'rules_config_access', danielebarchiesi@4: 'access arguments' => array('update', $base_count + 1), danielebarchiesi@4: 'file' => 'rules_scheduler.admin.inc', danielebarchiesi@4: 'file path' => drupal_get_path('module', 'rules_scheduler'), danielebarchiesi@4: ); danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * Control access to Rules configurations. danielebarchiesi@4: * danielebarchiesi@4: * Modules may implement this hook if they want to have a say in whether or not danielebarchiesi@4: * a given user has access to perform a given operation on a Rules danielebarchiesi@4: * configuration. danielebarchiesi@4: * danielebarchiesi@4: * @param $op danielebarchiesi@4: * The operation being performed. One of 'view', 'create', 'update' or danielebarchiesi@4: * 'delete'. danielebarchiesi@4: * @param $rules_config danielebarchiesi@4: * (optional) A Rules configuration to check access for. If nothing is given, danielebarchiesi@4: * access for all Rules configurations is determined. danielebarchiesi@4: * @param $account danielebarchiesi@4: * (optional) The user to check for. If no account is passed, access is danielebarchiesi@4: * determined for the current user. danielebarchiesi@4: * @return boolean danielebarchiesi@4: * Return TRUE to grant access, FALSE to explicitly deny access. Return NULL danielebarchiesi@4: * or nothing to not affect the operation. danielebarchiesi@4: * Access is granted as soon as a module grants access and no one denies danielebarchiesi@4: * access. Thus if no module explicitly grants access, access will be denied. danielebarchiesi@4: * danielebarchiesi@4: * @see rules_config_access() danielebarchiesi@4: */ danielebarchiesi@4: function hook_rules_config_access($op, $rules_config = NULL, $account = NULL) { danielebarchiesi@4: // Instead of returning FALSE return nothing, so others still can grant danielebarchiesi@4: // access. danielebarchiesi@4: if (isset($rules_config) && $rules_config->owner == 'mymodule' && user_access('my modules permission')) { danielebarchiesi@4: return TRUE; danielebarchiesi@4: } danielebarchiesi@4: } danielebarchiesi@4: danielebarchiesi@4: /** danielebarchiesi@4: * @} danielebarchiesi@4: */