You are here

function rules_condition_entity_has_field_assertions in Rules 7.2

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

Related topics

File

modules/entity.rules.inc, line 489
General entity related rules integration.

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,
      );
    }
  }
}