You are here

public function ConfigEntityQuery::execute in Configuration Views 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/views/query/ConfigEntityQuery.php \Drupal\config_views\Plugin\views\query\ConfigEntityQuery::execute()

Executes query and fills the associated view object with according values.

Values to set: $view->result, $view->total_rows, $view->execute_time, $view->pager['current_page'].

$view->result should contain an array of objects. The array must use a numeric index starting at 0.

Parameters

\Drupal\views\ViewExecutable $view: The view which is executed.

Overrides Sql::execute

File

src/Plugin/views/query/ConfigEntityQuery.php, line 105

Class

ConfigEntityQuery
This query is able to work with config entities.

Namespace

Drupal\config_views\Plugin\views\query

Code

public function execute(ViewExecutable $view) {
  $this->group_operator = isset($this->group_operator) ? $this->group_operator : 'AND';
  $base_table = $this->view->storage
    ->get('base_table');
  $data = \Drupal::service('views.views_data')
    ->get($base_table);
  $entity_type = $data['table']['entity type'];
  $query = \Drupal::entityQuery($entity_type, $this->group_operator);
  $this->entityConditionGroups = [
    $query,
  ];
  $this
    ->buildConditions();
  $this
    ->buildSorting($query);
  $ids = $query
    ->execute();
  $results = \Drupal::entityTypeManager()
    ->getStorage($entity_type)
    ->loadMultiple($ids);
  $index = 0;

  /* @var \Drupal\Core\Config\Entity\ConfigEntityBase $result */
  foreach ($results as $result) {

    // @todo: toArray() doesn't return all properties.
    $entity = $result
      ->toArray();
    $entity['type'] = $entity_type;
    $entity['entity'] = $result;

    // 'index' key is required.
    $entity['index'] = $index++;
    $view->result[] = new ResultRow($entity);
  }
  $view->total_rows = count($view->result);
  $view->execute_time = 0;
}