You are here

public function SensorListBuilder::buildRow in Monitoring 8

Builds a row for an entity in the entity listing.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.

Return value

array A render array structure of fields for this entity.

Overrides EntityListBuilder::buildRow

See also

\Drupal\Core\Entity\EntityListBuilder::render()

1 call to SensorListBuilder::buildRow()
SensorListBuilder::buildForm in src/SensorListBuilder.php
Form constructor.

File

src/SensorListBuilder.php, line 45
Contains \Drupal\monitoring\SensorListBuilder.

Class

SensorListBuilder
Defines a class to build a listing of sensor config entities.

Namespace

Drupal\monitoring

Code

public function buildRow(EntityInterface $entity) {

  /** @var \Drupal\monitoring\Entity\SensorConfig $entity */
  $row['category']['data'] = $entity
    ->getCategory();
  $row['category']['class'][] = 'table-filter-category';
  $row['label']['data'] = $entity
    ->label();
  $row['label']['class'][] = 'table-filter-text-source';
  $plugin_definition = monitoring_sensor_manager()
    ->getSensorConfigByName($entity
    ->id())
    ->getPlugin()
    ->getPluginDefinition();
  $row['description']['data'] = array(
    '#type' => 'details',
    '#title' => $entity
      ->getDescription() ?: $this
      ->t('Details'),
    '#open' => FALSE,
    '#tree' => TRUE,
    '#attributes' => array(
      'class' => array(
        'monitoring-sensor-details',
      ),
    ),
  );
  $row['description']['data'][$entity
    ->id()]['id'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Sensor ID'),
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
    '#markup' => '<span class="table-filter-text-source">' . $entity
      ->id() . '</span>',
  ];
  $row['description']['data'][$entity
    ->id()]['sensor_type'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Sensor type'),
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
    '#markup' => '<span class="table-filter-sensor-type">' . $plugin_definition['label'] . '</span>',
  ];
  $url = Url::fromRoute('entity.monitoring_sensor_config.details_form', array(
    'monitoring_sensor_config' => $entity
      ->id(),
  ));
  $row = $row + parent::buildRow($entity);

  // Adds the link to details page if sensor is enabled.

  /** @var \Drupal\monitoring\Entity\SensorConfig $sensor_config */
  $sensor_config = SensorConfig::load($entity
    ->id());
  if ($sensor_config
    ->isEnabled()) {
    $row['operations']['data']['#links']['details'] = array(
      'title' => 'Details',
      'url' => $url,
    );
  }
  return $row;
}