You are here

public function Xml::execute in Views XML Backend 8

Executes the 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

view $view: The view which is executed.

Overrides QueryPluginBase::execute

File

src/Plugin/views/query/Xml.php, line 381
Contains \Drupal\views_xml_backend\Plugin\views\query\Xml.

Class

Xml
Views query plugin for an XML query.

Namespace

Drupal\views_xml_backend\Plugin\views\query

Code

public function execute(ViewExecutable $view) {

  // When creating a new view, there won't be a query set yet.
  if ($view->build_info['query'] === '') {
    $this->messenger
      ->setMessage($this
      ->t('Please configure the query settings.'), 'warning');
    return;
  }
  $start = microtime(TRUE);
  libxml_clear_errors();
  $use_errors = libxml_use_internal_errors(TRUE);
  $this
    ->doExecute($view);
  if ($this->livePreview && $this->options['show_errors']) {
    foreach (libxml_get_errors() as $error) {
      $type = $error->level === LIBXML_ERR_FATAL ? 'error' : 'warning';
      $args = [
        '%error' => trim($error->message),
        '%num' => $error->line,
        '%code' => $error->code,
      ];
      $this->messenger
        ->setMessage($this
        ->t('%error on line %num. Error code: %code', $args), $type);
    }
  }
  libxml_use_internal_errors($use_errors);
  libxml_clear_errors();
  $view->execute_time = microtime(TRUE) - $start;
}