/** * Adds a condition to an already built SelectQuery (internal function). * * This is a helper for hook_entity_query() and hook_field_storage_query(). * * @param SelectQuery $select_query * A SelectQuery object. * @param string $sql_field * The name of the field. * @param array $condition * A condition as described in EntityFieldQuery::fieldCondition() and * EntityFieldQuery::entityCondition(). * @param bool $having * HAVING or WHERE. This is necessary because SQL can't handle WHERE * conditions on aliased columns. */ public function addCondition(SelectQuery $select_query, $sql_field, $condition, $having = FALSE) { $needs_or = !empty($condition['or']) || in_array($condition['operator'], static::$leftJoinOperators); if (in_array($condition['operator'], array('CONTAINS', 'STARTS_WITH')) || !$needs_or) { parent::addCondition($select_query, $sql_field, $condition, $having); return; } $method = $having ? 'havingCondition' : 'condition'; $db_or = db_or()->condition($sql_field, $condition['value'], $condition['operator']); if (strtoupper($condition['operator']) != 'IS NULL' && strtoupper($condition['operator']) != 'IS NOT NULL') { $db_or->condition($sql_field, NULL, 'IS NULL'); } $select_query->{$method}($db_or); }