You are here

public function AlphaPagination::ensureQuery in Views Alpha Pagination 8.2

Extract the SQL query from the query information.

Once extracted, place it into the options array so it is passed to the render function. This code was lifted nearly verbatim from the views module where the query is constructed for the ui to show the query in the administrative area.

@todo Need to make this better somehow?

2 calls to AlphaPagination::ensureQuery()
AlphaPagination::getCid in src/AlphaPagination.php
Retrieves a cache identifier for the view, display and query, if set.
AlphaPagination::getEntityIds in src/AlphaPagination.php
Construct the actual SQL query for the view being generated.

File

src/AlphaPagination.php, line 243

Class

AlphaPagination
A base views handler for alpha pagination.

Namespace

Drupal\alpha_pagination

Code

public function ensureQuery() {
  if (!$this
    ->getOption('query') && !empty($this->handler->view->build_info['query'])) {

    /** @var \SelectQuery $query */
    $query = $this->handler->view->build_info['query'];
    $quoted = $query
      ->getArguments();
    foreach ($quoted as $key => $val) {
      if (is_array($val)) {
        $quoted[$key] = implode(', ', array_map([
          $this->database,
          'quote',
        ], $val));
      }
      else {
        $quoted[$key] = $this->database
          ->quote($val);
      }
    }
    $this->handler->options['query'] = Html::escape(strtr($query, $quoted));
  }
}