home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (rules_test.rules_defaults.inc)

This example Drupal source code file (rules_test.rules_defaults.inc) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

been, comment:node, error, function, has, label, level, node, page, php, return, rule, type, value

The rules_test.rules_defaults.inc Drupal example source code

<?php
// $Id: rules_test.rules_defaults.inc,v 1.1.2.4 2011/01/13 18:06:48 fago Exp $

/**
 * @file Includes any rules integration provided by the module.
 */


/**
 * Implements hook_default_rules_configuration().
 */
function rules_test_default_rules_configuration() {
  $rule = rules_reaction_rule();
  $rule->label = 'example default rule';
  $rule->active = FALSE;
  $rule->event('node_update')
       ->condition(rules_condition('data_is', array('data:select' => 'node:status', 'value' => TRUE))->negate())
       ->condition('data_is', array('data:select' => 'node:type', 'value' => 'page'))
       ->action('drupal_message', array('message' => 'A node has been updated.'));

  $configs['rules_test_default_1'] = $rule;

  $action_set = rules_action_set(array('node' => array('type' => 'node', 'label' => 'Content')));
  $action_set->action('node_publish');
  $configs['rules_test_action_set'] = $action_set;

  // Test providing a rule using an export.
  $configs['rules_export_test'] = rules_import(_rules_export_get_test_export());

  return $configs;
}

/**
 * Defines the export of rule for testing import/export.
 */
function _rules_export_get_test_export() {
  return '{ "rules_export_test" : {
    "LABEL" : "Test import rule2",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "-1",
    "ACTIVE" : false,
    "REQUIRES" : [ "rules", "comment" ],
    "ON" : [ "comment_insert" ],
    "IF" : [
      { "OR" : [
          { "NOT node_is_sticky" : { "node" : [ "comment:node" ] } },
          { "node_is_of_type" : {
              "node" : [ "comment:node" ],
              "type" : { "value" : { "page" : "page" } }
            }
          }
        ]
      }
    ],
    "DO" : [
      { "data_set" : {
          "data" : [ "comment:node:created" ],
          "value" : { "select" : "site:current-date", "date_offset" : { "value" : -604800 } }
        }
      },
      { "node_make_sticky" : { "node" : [ "comment:node" ] } },
      { "variable_add" : {
          "USING" : { "type" : "token", "value" : "error" },
          "PROVIDE" : { "variable_added" : { "level" : "Error level" } }
        }
      },
      { "drupal_message" : {
          "message" : "fein, [comment:node:title] has been made sticky!",
          "type" : [ "level" ]
        }
      }
    ]
  }
}';
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal rules_test.rules_defaults.inc source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.