You are here

public function SensorName::render in Monitoring 8

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides FieldPluginBase::render

File

src/Plugin/views/field/SensorName.php, line 29
Contains \Drupal\monitoring\Plugin\views\field\SensorName.

Class

SensorName
Defines a field handler that turns sensor machine name into a clickable link with the sensor label as the show text.

Namespace

Drupal\monitoring\Plugin\views\field

Code

public function render(ResultRow $values) {
  $value = $this
    ->getValue($values);
  try {
    $sensor_config = monitoring_sensor_manager()
      ->getSensorConfigByName($value);
    $label = $sensor_config
      ->getLabel();
  } catch (NonExistingSensorException $e) {
    $label = t('Disappeared sensor @name', array(
      '@name' => $value,
    ));
  }
  return Link::fromTextAndUrl($label, Url::fromRoute('entity.monitoring_sensor_config.details_form', array(
    'monitoring_sensor_config' => $value,
  )))
    ->toString();
}