Condition::compile

public Condition::compile($configs)

Compiles this conditional clause.

Parameters

$query: The query object this conditional clause belongs to.

Overrides ConditionInterface::compile

File

core/lib/Drupal/Core/Config/Entity/Query/Condition.php, line 20

Class

Condition
Defines the condition class for the config entity query.

Namespace

Drupal\Core\Config\Entity\Query

Code

public function compile($configs) {
  $and = strtoupper($this->conjunction) == 'AND';
  $single_conditions = array();
  $condition_groups = array();
  foreach ($this->conditions as $condition) {
    if ($condition['field'] instanceof ConditionInterface) {
      $condition_groups[] = $condition;
    }
    else {
      if (!isset($condition['operator'])) {
        $condition['operator'] = is_array($condition['value']) ? 'IN' : '=';
      }

      // Lowercase condition value(s) for case-insensitive matches.
      if (is_array($condition['value'])) {
        $condition['value'] = array_map('Drupal\Component\Utility\Unicode::strtolower', $condition['value']);
      }
      elseif (!is_bool($condition['value'])) {
        $condition['value'] = Unicode::strtolower($condition['value']);
      }

      $single_conditions[] = $condition;
    }
  }
  $return = array();
  if ($single_conditions) {
    foreach ($configs as $config_name => $config) {
      foreach ($single_conditions as $condition) {
        $match = $this->matchArray($condition, $config, explode('.', $condition['field']));
        // If AND and it's not matching, then the rest of conditions do not
        // matter and this config object does not match.
        // If OR and it is matching, then the rest of conditions do not
        // matter and this config object does match.
        if ($and != $match) {
          break;
        }
      }
      if ($match) {
        $return[$config_name] = $config;
      }
    }
  }
  elseif (!$condition_groups || $and) {
    // If there were no single conditions then either:
    // - Complex conditions, OR: need to start from no entities.
    // - Complex conditions, AND: need to start from all entities.
    // - No complex conditions (AND/OR doesn't matter): need to return all
    //   entities.
    $return = $configs;
  }
  foreach ($condition_groups as $condition) {
    $group_entities = $condition['field']->compile($configs);
    if ($and) {
      $return = array_intersect_key($return, $group_entities);
    }
    else {
      $return = $return + $group_entities;
    }
  }

  return $return;
}
doc_Drupal
2016-10-29 08:51:47
Comments
Leave a Comment

Please login to continue.