You are here

function _rules_admin_install_example_rules in Rules 6

2 calls to _rules_admin_install_example_rules()
rules_admin_install in rules_admin/rules_admin.install
Implementation of hook_install().
rules_admin_update_6001 in rules_admin/rules_admin.install
Update 6001 Example rules are now added by hook_install() instead of using default rules.

File

rules_admin/rules_admin.install, line 24
Rules Admin UI - Installation file.

Code

function _rules_admin_install_example_rules() {
  $rule = array(
    '#type' => 'rule',
    '#set' => 'event_node_view',
    '#label' => t('Example rule: When viewing an unpublished page, publish it.'),
    '#status' => 'custom',
    '#categories' => array(
      'example',
    ),
    '#active' => 0,
  );
  $condition1 = rules_use_condition('rules_condition_content_is_published', array(
    '#settings' => array(
      '#argument map' => array(
        'node' => 'node',
      ),
    ),
    '#negate' => 1,
  ), t('Viewed content is published'));
  $condition2 = rules_use_condition('rules_condition_content_is_type', array(
    '#settings' => array(
      '#argument map' => array(
        'node' => 'node',
      ),
      'type' => array(
        'page',
      ),
    ),
  ), t('Viewed content is Page'));
  $action1 = rules_use_action('rules_core_node_publish_action', array(
    '#settings' => array(
      '#argument map' => array(
        'node' => 'node',
      ),
      'auto_save' => TRUE,
    ),
  ), t('Publish viewed content'));
  $rule += array(
    '#conditions' => array(
      $condition1,
      $condition2,
    ),
    '#actions' => array(
      $action1,
    ),
  );
  rules_item_save('rules', 'rules_example_1', $rule);
}