Coverage index

src/Plugin/views/field/AiAgent.php

Lines: 100.00%

LineHitsSource
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Drupal\visitors\Plugin\views\field;
6
7
use Drupal\views\Attribute\ViewsField;
8
use Drupal\views\Plugin\views\field\FieldPluginBase;
9
use Drupal\views\ResultRow;
10
11
/**
12
 * Labels a visit as human or AI agent.
13
 */
14
#[ViewsField('visitors_ai_agent')]
15
final class AiAgent extends FieldPluginBase {
16
17
  /**
18
   * {@inheritdoc}
19
   */
20
  public function render(ResultRow $values) {
211
    $value = $this->getValue($values);
221
    if ((string) $value === '1') {
231
      return $this->t('AI agent');
24
    }
251
    return $this->t('Human');
26
  }
27
28
}