diff --git a/modules/entity.eval.inc b/modules/entity.eval.inc index 6ae5331..5dc68af 100644 --- a/modules/entity.eval.inc +++ b/modules/entity.eval.inc @@ -157,3 +157,11 @@ function rules_condition_entity_has_field($wrapper, $field_name, $settings, $sta function rules_condition_entity_is_of_type($wrapper, $type) { return $wrapper->type() == $type; } + +/** + * 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 4d16907..43f5cc6 100644 --- a/modules/entity.rules.inc +++ b/modules/entity.rules.inc @@ -348,6 +348,31 @@ function rules_entity_condition_info() { 'group' => t('Entities'), 'base' => 'rules_condition_entity_is_of_type', ), + '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('The type of entity to test for.'), + 'restriction' => 'input', + ), + 'property' => array( + 'type' => 'text', + 'label' => t('Property'), + 'description' => t('The entity property to test for.'), + 'restriction' => 'input', + ), + 'value' => array( + 'type' => 'unknown', + 'label' => t('Value'), + 'description' => t('The entity property value to test for.'), + ), + ), + 'group' => t('Entities'), + 'base' => 'rules_condition_entity_exists', + ), ); }