Query.php in Zircon Profile 8.0
File
core/lib/Drupal/Core/Entity/KeyValueStore/Query/Query.php
View source
<?php
namespace Drupal\Core\Entity\KeyValueStore\Query;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Query\QueryBase;
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
class Query extends QueryBase {
protected $keyValueFactory;
public function __construct(EntityTypeInterface $entity_type, $conjunction, array $namespaces, KeyValueFactoryInterface $key_value_factory) {
parent::__construct($entity_type, $conjunction, $namespaces);
$this->keyValueFactory = $key_value_factory;
}
public function execute() {
$records = $this->keyValueFactory
->get('entity_storage__' . $this->entityTypeId)
->getAll();
$result = $this->condition
->compile($records);
foreach ($this->sort as $sort) {
$direction = $sort['direction'] == 'ASC' ? -1 : 1;
$field = $sort['field'];
uasort($result, function ($a, $b) use ($field, $direction) {
return $a[$field] <= $b[$field] ? $direction : -$direction;
});
}
$this
->initializePager();
if ($this->range) {
$result = array_slice($result, $this->range['start'], $this->range['length'], TRUE);
}
if ($this->count) {
return count($result);
}
$entity_ids = array_keys($result);
return array_combine($entity_ids, $entity_ids);
}
}
Classes
Name |
Description |
Query |
Defines the entity query for entities stored in a key value backend. |