From f8092155ef5f323317529dc9f255425d30485e2c Mon Sep 17 00:00:00 2001
From: jucallme <jucallme@30440.no-reply.drupal.org>
Date: Tue, 28 May 2013 16:59:26 -0400
Subject: [PATCH] Entity exists by property

---
 modules/entity.eval.inc  |  8 ++++++++
 modules/entity.rules.inc | 30 ++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/modules/entity.eval.inc b/modules/entity.eval.inc
index 0f4c36a..4623a28 100644
--- a/modules/entity.eval.inc
+++ b/modules/entity.eval.inc
@@ -172,3 +172,11 @@ function rules_condition_entity_field_access(EntityDrupalWrapper $wrapper, $fiel
   $field = field_info_field($field_name);
   return !empty($field) && field_access($op, $field, $wrapper->type(), $wrapper->value(), $account = NULL);
 }
+
+/**
+ * Condition: Entity exists with the matching property value.
+ */
+function rules_condition_entity_exists($type, $property, $value) {
+  $result = entity_property_query($type, $property, $value, 1);
+  return !empty($result);
+}
diff --git a/modules/entity.rules.inc b/modules/entity.rules.inc
index 76ec4ee..6dda7f9 100644
--- a/modules/entity.rules.inc
+++ b/modules/entity.rules.inc
@@ -428,6 +428,36 @@ function rules_entity_condition_info() {
       'group' => t('Entities'),
       'base' => 'rules_condition_entity_field_access',
     ),
+    'entity_exists' => array(
+      'label' => t('Entity exists by property'),
+      'parameter' => array(
+        'type' => array(
+          'type' => 'text',
+          'label' => t('Entity type'),
+          'options list' => 'rules_entity_action_type_options',
+          'description' => t('Specifies the type of the entity that should be fetched.'),
+          'restriction' => 'input',
+        ),
+        'property' => array(
+          'type' => 'text',
+          'label' => t('Property'),
+          'options list' => 'rules_action_entity_query_property_options_list',
+          'description' => t('The entity property to test for.'),
+          'restriction' => 'input',
+        ),
+        'value' => array(
+          'type' => 'unknown',
+          'label' => t('Value'),
+          'description' => t('The property value of the entity to be fetched.'),
+        ),
+      ),
+      'group' => t('Entities'),
+      'access callback' => 'rules_entity_action_access',
+      'base' => 'rules_condition_entity_exists',
+      'callbacks' => array(
+        'form_alter' => 'rules_action_type_form_alter',
+      ),
+    ),
   );
 }
 
-- 
1.7.11.3

