function rules_condition_entity_has_field_assertions

Assert that the entity has the field, if there is metadata for the field.

Related topics

File

modules/entity.rules.inc, line 489

Code

function rules_condition_entity_has_field_assertions($element) {
    // Assert the field is there if the condition matches.
    if ($wrapper = $element->applyDataSelector($element->settings['entity:select'])) {
        $type = $wrapper->type();
        $field_property = $element->settings['field'];
        // Get all possible properties and check whether we have one for the field.
        $properties = entity_get_all_property_info($type == 'entity' ? NULL : $type);
        if (isset($properties[$field_property])) {
            $assertion = array(
                'property info' => array(
                    $field_property => $properties[$field_property],
                ),
            );
            return array(
                $element->settings['entity:select'] => $assertion,
            );
        }
    }
}