public function QueryTest::execute

Implements Drupal\views\Plugin\views\query\QueryPluginBase::execute().

Overrides QueryPluginBase::execute

File

drupal/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/query/QueryTest.php, line 102
Definition of Drupal\views_test_data\Plugin\views\query\QueryTest.

Class

QueryTest
Defines a query test plugin.

Namespace

Drupal\views_test_data\Plugin\views\query

Code

public function execute(ViewExecutable $view) {
  $result = array();
  foreach ($this->allItems as $element) {

    // Run all conditions on the element, and add it to the result if they
    // match.
    $match = TRUE;
    foreach ($this->conditions as $condition) {
      $match &= $this
        ->match($element, $condition);
    }
    if ($match) {

      // If the query explicit defines fields to use, filter all others out.
      // Filter out fields
      if ($this->fields) {
        $element = array_intersect_key($element, $this->fields);
      }
      $result[] = (object) $element;
    }
  }
  $this->view->result = $result;
}