protected function EntityFieldQuery::addFieldCondition

You are here

7 entity.inc protected EntityFieldQuery::addFieldCondition(&$conditions, $field, $column = NULL, $value = NULL, $operator = NULL, $delta_group = NULL, $language_group = NULL)

Adds the given condition to the proper condition array.

Parameters

$conditions: A reference to an array of conditions.

$field: Either a field name or a field array.

$column: A column defined in the hook_field_schema() of this field. If this is omitted then the query will find only entities that have data in this field, using the entity and property conditions if there are any.

$value: The value to test the column value against. In most cases, this is a scalar. For more complex options, it is an array. The meaning of each element in the array is dependent on $operator.

$operator: Possible values:

  • '=', '<>', '>', '>=', '<', '<=', 'STARTS_WITH', 'CONTAINS': These operators expect $value to be a literal of the same type as the column.
  • 'IN', 'NOT IN': These operators expect $value to be an array of literals of the same type as the column.
  • 'BETWEEN': This operator expects $value to be an array of two literals of the same type as the column.

The operator can be omitted, and will default to 'IN' if the value is an array, or to '=' otherwise.

$delta_group: An arbitrary identifier: conditions in the same group must have the same $delta_group. For example, let's presume a multivalue field which has two columns, 'color' and 'shape', and for entity id 1, there are two values: red/square and blue/circle. Entity ID 1 does not have values corresponding to 'red circle', however if you pass 'red' and 'circle' as conditions, it will appear in the results - by default queries will run against any combination of deltas. By passing the conditions with the same $delta_group it will ensure that only values attached to the same delta are matched, and entity 1 would then be excluded from the results.

$language_group: An arbitrary identifier: conditions in the same group must have the same $language_group.

Return value

EntityFieldQuery The called object.

3 calls to EntityFieldQuery::addFieldCondition()
EntityFieldQuery::fieldCondition in includes/entity.inc
Adds a condition on field values.
EntityFieldQuery::fieldDeltaCondition in includes/entity.inc
Adds a condition on the field delta column.
EntityFieldQuery::fieldLanguageCondition in includes/entity.inc
Adds a condition on the field language column.

File

includes/entity.inc, line 756

Class

EntityFieldQuery
Retrieves entities matching a given set of conditions.

Code

protected function addFieldCondition(&$conditions, $field, $column = NULL, $value = NULL, $operator = NULL, $delta_group = NULL, $language_group = NULL) {
  // The '!=' operator is deprecated in favour of the '<>' operator since the
  // latter is ANSI SQL compatible.
  if ($operator == '!=') {
    $operator = '<>';
  }
  if (is_scalar($field)) {
    $field_definition = field_info_field($field);
    if (empty($field_definition)) {
      throw new EntityFieldQueryException(t('Unknown field: @field_name', array('@field_name' => $field)));
    }
    $field = $field_definition;
  }
  // Ensure the same index is used for field conditions as for fields.
  $index = count($this->fields);
  $this->fields[$index] = $field;
  if (isset($column)) {
    $conditions[$index] = array(
      'field' => $field,
      'column' => $column,
      'value' => $value,
      'operator' => $operator,
      'delta_group' => $delta_group,
      'language_group' => $language_group,
    );
  }
  return $this;
}

Comments

some examples would really help

I don't think this is intended to be used externally. EntityFieldQuery::fieldCondition() appears to be a wrapper for this function that is intended for external use.

need more exemples around delta_group