You are here

protected function ContentEntityAggregatorSensorPlugin::getEntityQuery in Monitoring 8

Builds the entity query for verbose output.

Similar to the aggregate query, but without aggregation.

Return value

\Drupal\Core\Entity\Query\QueryInterface The entity query object.

See also

\Drupal\monitoring\Plugin\monitoring\SensorPlugin\ContentEntityAggregatorSensorPlugin::getEntityQueryAggregate()

File

src/Plugin/monitoring/SensorPlugin/ContentEntityAggregatorSensorPlugin.php, line 112
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ContentEntityAggregatorSensorPlugin.

Class

ContentEntityAggregatorSensorPlugin
Content entity database aggregator.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

protected function getEntityQuery() {
  $entity_info = $this->entityTypeManager
    ->getDefinition($this->sensorConfig
    ->getSetting('entity_type'), TRUE);

  // Get query for the entity type.
  $query = $this->entityTypeManager
    ->getStorage($this->sensorConfig
    ->getSetting('entity_type'))
    ->getQuery()
    ->accessCheck(FALSE);

  // Add conditions.
  foreach ($this
    ->getConditions() as $condition) {
    if (empty($condition['field'])) {
      continue;
    }
    $query
      ->condition($condition['field'], $condition['value'], isset($condition['operator']) ? $condition['operator'] : NULL);
  }

  // Apply time interval on field.
  if ($this
    ->getTimeIntervalField() && $this
    ->getTimeIntervalValue()) {
    $query
      ->condition($this
      ->getTimeIntervalField(), \Drupal::time()
      ->getRequestTime() - $this
      ->getTimeIntervalValue(), '>');
  }

  // Order by most recent or id.
  if ($this
    ->getTimeIntervalField()) {
    $query
      ->sort($this
      ->getTimeIntervalField(), 'DESC');
  }
  else {
    $query
      ->sort($entity_info
      ->getKey('id'), 'DESC');
  }
  return $query;
}