From 608349c4435a19035439ac1bbb1a59e6a6aab7e4 Mon Sep 17 00:00:00 2001
From: Guillaume Viguier <guillaume@viguierjust.com>
Date: Wed, 1 Feb 2012 14:28:49 +0100
Subject: [PATCH] Issue #1424290: Rules integration for D7

---
 custom_pub.module    |   18 ++++++++++--------
 custom_pub.rules.inc |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 8 deletions(-)
 create mode 100644 custom_pub.rules.inc

diff --git a/custom_pub.module b/custom_pub.module
index 28b5318..4a3a01a 100644
--- a/custom_pub.module
+++ b/custom_pub.module
@@ -237,10 +237,7 @@ function custom_pub_on_action(&$node, &$context) {
  * Allows the user to pick custom publishing options to turn on.
  */
 function custom_pub_on_action_form($context) {
-  $types = variable_get('custom_pub_types', array());//get the current custom publishing types
-  foreach ($types as $type) {
-    $pub_types[$type['type']] = $type['name'];
-  }
+  $pub_types = custom_pub_types_list();
   $form['types'] = array(
     '#title' => t('Custom Publishing Options'),
     '#description' => t('Select the Custom publishing options to toggle on when this action is triggered.'),
@@ -284,10 +281,7 @@ function custom_pub_off_action(&$node, &$context) {
  * Allows the user to pick custom publishing options to turn off.
  */
 function custom_pub_off_action_form($context) {
-  $types = variable_get('custom_pub_types', array());//get the current custom publishing types
-  foreach ($types as $type) {
-    $pub_types[$type['type']] = $type['name'];
-  }
+  $pub_types = custom_pub_types_list();
   $form['types'] = array(
     '#title' => t('Custom Publishing Options'),
     '#description' => t('Select the Custom publishing options to toggle off when this action is triggered.'),
@@ -299,6 +293,14 @@ function custom_pub_off_action_form($context) {
   return $form;
 }
 
+function custom_pub_types_list() {
+  $types = variable_get('custom_pub_types', array());//get the current custom publishing types
+  foreach ($types as $type) {
+    $pub_types[$type['type']] = $type['name'];
+  }
+  return $pub_types;
+}
+
 function custom_pub_off_action_submit($form, &$form_state) {
   return array('types' => $form_state['values']['types']);
 }
diff --git a/custom_pub.rules.inc b/custom_pub.rules.inc
new file mode 100644
index 0000000..4a85c7c
--- /dev/null
+++ b/custom_pub.rules.inc
@@ -0,0 +1,39 @@
+<?php
+
+
+/**
+ * @file
+ * Rules integration with custom publishing options module.
+ *
+ * @addtogroup rules
+ * @{
+ */
+
+/**
+ * Implements hook_rules_condition_info()
+ */
+function custom_pub_rules_condition_info() {
+  $items = array();
+  $items['custom_pub_node_has_option'] = array(
+    'label' => t('Content has custom publishing option'),
+    'parameter' => array(
+      'node' => array(
+        'type' => 'node',
+        'label' => t('Content'),
+      ),
+      'option' => array(
+        'type' => 'text',
+        'label' => t('Custom publishing option'),
+        'options list' => 'custom_pub_types_list',
+      ),
+    ),
+    'group' => t('Node'),
+    'access callback' => 'rules_node_integration_access',
+    'base' => 'custom_pub_rules_condition_node_has_option',
+  );
+  return $items;
+}
+
+function custom_pub_rules_condition_node_has_option($node, $option) {
+  return (bool)$node->$option;
+}
-- 
1.7.5.4

