Lines: 100.00%
| Line | Hits | Source |
|---|---|---|
| 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) { | |
| 26 | 1 | $months = [ |
| 27 | 1 | 1 => $this->t('January'), |
| 28 | 1 | 2 => $this->t('February'), |
| 29 | 1 | 3 => $this->t('March'), |
| 30 | 1 | 4 => $this->t('April'), |
| 31 | 1 | 5 => $this->t('May'), |
| 32 | 1 | 6 => $this->t('June'), |
| 33 | 1 | 7 => $this->t('July'), |
| 34 | 1 | 8 => $this->t('August'), |
| 35 | 1 | 9 => $this->t('September'), |
| 36 | 1 | 10 => $this->t('October'), |
| 37 | 1 | 11 => $this->t('November'), |
| 38 | 1 | 12 => $this->t('December'), |
| 39 | 1 | ]; |
| 40 | ||
| 41 | 1 | $value = $this->getValue($values); |
| 42 | 1 | $year = substr($value, 2, 2); |
| 43 | 1 | $month = (int) substr($value, 4, 2); |
| 44 | ||
| 45 | 1 | $output = $months[$month] . " '" . $year; |
| 46 | ||
| 47 | 1 | return ViewsRenderPipelineMarkup::create(UtilityXss::filterAdmin($output)); |
| 48 | } | |
| 49 | ||
| 50 | } |