Skip navigation
Help

EntityFieldQuery::addCondition

7 entity.inc public EntityFieldQuery::addCondition(SelectQuery $select_query, $sql_field, $condition, $having = FALSE)

Adds a condition to an already built SelectQuery (internal function).

This is a helper for hook_entity_query() and hook_field_storage_query().

Parameters

SelectQuery $select_query: A SelectQuery object.

$sql_field: The name of the field.

$condition: A condition as described in EntityFieldQuery::fieldCondition() and EntityFieldQuery::entityCondition().

$having: HAVING or WHERE. This is necessary because SQL can't handle WHERE conditions on aliased columns.

1 call to EntityFieldQuery::addCondition()

File

drupal/includes/entity.inc, line 1315

Code

public function addCondition(SelectQuery $select_query, $sql_field, $condition, $having = FALSE) {
  $method = $having ? 'havingCondition' : 'condition';
  $like_prefix = '';
  switch ($condition['operator']) {
    case 'CONTAINS':
      $like_prefix = '%';
    case 'STARTS_WITH':
      $select_query->$method($sql_field, $like_prefix . db_like($condition['value']) . '%', 'LIKE');
      break;
    default:
      $select_query->$method($sql_field, $condition['value'], $condition['operator']);
  }
}