Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
VisitorsMonth
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 render
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Drupal\visitors\Plugin\views\field;
4
5use Drupal\Component\Utility\Xss as UtilityXss;
6use Drupal\views\Render\ViewsRenderPipelineMarkup;
7
8/**
9 * Field handler to display the hour (server) of the visit.
10 *
11 * @ingroup views_field_handlers
12 *
13 * @ViewsField("visitors_month")
14 */
15final class VisitorsMonth extends VisitorsTimestamp {
16
17  /**
18   * {@inheritdoc}
19   */
20  protected $format = 'Ym';
21
22  /**
23   * {@inheritdoc}
24   */
25  public function render($values) {
26    $months = [
27      1 => $this->t('January'),
28      2 => $this->t('February'),
29      3 => $this->t('March'),
30      4 => $this->t('April'),
31      5 => $this->t('May'),
32      6 => $this->t('June'),
33      7 => $this->t('July'),
34      8 => $this->t('August'),
35      9 => $this->t('September'),
36      10 => $this->t('October'),
37      11 => $this->t('November'),
38      12 => $this->t('December'),
39    ];
40
41    $value = $this->getValue($values);
42    $year = substr($value, 2, 2);
43    $month = (int) substr($value, 4, 2);
44
45    $output = $months[$month] . " '" . $year;
46
47    return ViewsRenderPipelineMarkup::create(UtilityXss::filterAdmin($output));
48  }
49
50}