You are here

protected function FarmMetricsBlock::getEntityMetrics in farmOS 2.x

Gather metrics for rendering in the block.

Parameters

string $entity_type: The entity type machine name.

Return value

array Returns an array of metric information.

1 call to FarmMetricsBlock::getEntityMetrics()
FarmMetricsBlock::build in modules/core/ui/metrics/src/Plugin/Block/FarmMetricsBlock.php
Builds and returns the renderable array for this block plugin.

File

modules/core/ui/metrics/src/Plugin/Block/FarmMetricsBlock.php, line 135

Class

FarmMetricsBlock
Provides a 'Metrics' block.

Namespace

Drupal\farm_ui_metrics\Plugin\Block

Code

protected function getEntityMetrics($entity_type) {
  $metrics = [];

  // Load bundles.
  $bundles = $this->bundleInfo
    ->getBundleInfo($entity_type);

  // Count records by type.
  foreach ($bundles as $bundle => $bundle_info) {
    $count = $this->entityTypeManager
      ->getStorage($entity_type)
      ->getAggregateQuery()
      ->accessCheck(TRUE)
      ->condition('type', $bundle)
      ->count()
      ->execute();
    $route_name = "view.farm_{$entity_type}.page_type";
    $metrics[] = Link::createFromRoute($bundle_info['label'] . ': ' . $count, $route_name, [
      'arg_0' => $bundle,
    ], [
      'attributes' => [
        'class' => [
          'metric',
          'button',
        ],
      ],
    ])
      ->toString();
  }
  return $metrics;
}