Coverage index

src/Plugin/views/field/VisitorsMonth.php

Lines: 100.00%

LineHitsSource
1
<?php
2
3
namespace Drupal\visitors\Plugin\views\field;
4
5
use Drupal\Component\Utility\Xss as UtilityXss;
6
use Drupal\views\Attribute\ViewsField;
7
use Drupal\views\Render\ViewsRenderPipelineMarkup;
8
9
/**
10
 * Field handler to display the month of the visit.
11
 *
12
 * @ingroup views_field_handlers
13
 */
14
#[ViewsField("visitors_month")]
15
final class VisitorsMonth extends VisitorsTimestamp {
16
17
  /**
18
   * {@inheritdoc}
19
   */
20
  protected $format = 'Ym';
21
22
  /**
23
   * {@inheritdoc}
24
   */
25
  public function render($values) {
261
    $months = [
271
      1 => $this->t('January'),
281
      2 => $this->t('February'),
291
      3 => $this->t('March'),
301
      4 => $this->t('April'),
311
      5 => $this->t('May'),
321
      6 => $this->t('June'),
331
      7 => $this->t('July'),
341
      8 => $this->t('August'),
351
      9 => $this->t('September'),
361
      10 => $this->t('October'),
371
      11 => $this->t('November'),
381
      12 => $this->t('December'),
391
    ];
40
411
    $value = $this->getValue($values);
421
    $year = substr($value, 2, 2);
431
    $month = (int) substr($value, 4, 2);
44
451
    $output = $months[$month] . " '" . $year;
46
471
    return ViewsRenderPipelineMarkup::create(UtilityXss::filterAdmin($output));
48
  }
49
50
}