You are here

public function ViewDisplayAggregatorSensorPlugin::resultVerbose in Monitoring 8

Provide additional info about sensor call.

This method is only executed on request. It is guaranteed that runSensor() is executed before this method.

Parameters

\Drupal\monitoring\Result\SensorResultInterface $result: Sensor result.

Return value

array Sensor call verbose info as render array.

Overrides ExtendedInfoSensorPluginInterface::resultVerbose

File

src/Plugin/monitoring/SensorPlugin/ViewDisplayAggregatorSensorPlugin.php, line 36
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ViewDisplayAggregatorSensorPlugin.

Class

ViewDisplayAggregatorSensorPlugin
Execute a view display and count the results.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

public function resultVerbose(SensorResultInterface $result) {
  $output = [];
  $view_executable = Views::getView($this->sensorConfig
    ->getSetting('view'));
  $display_id = $this->sensorConfig
    ->getSetting('display');
  $view_executable
    ->setDisplay($display_id);
  $view_executable
    ->initDisplay();
  $view_executable
    ->setAjaxEnabled(TRUE);

  // Force ajax mode for the view.
  $display = $view_executable->displayHandlers
    ->get($display_id);
  $display
    ->setOption('use_ajax', TRUE);

  // Get the preview of the view for current display.
  $preview = $view_executable
    ->preview($display_id);

  // Get the query and arguments of the view.
  $query = $view_executable
    ->getQuery()
    ->query();
  $arguments = $query
    ->arguments();
  $output['query'] = array(
    '#type' => 'item',
    '#title' => t('Query'),
    '#markup' => '<pre>' . $query . '</pre>',
  );
  $output['arguments'] = array(
    '#type' => 'item',
    '#title' => t('Arguments'),
    '#markup' => '<pre>' . var_export($arguments, TRUE) . '</pre>',
  );
  $output['view'] = array(
    '#type' => 'fieldset',
    '#title' => t('View preview'),
  );
  $output['view']['preview'] = $preview;
  return $output;
}