Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
UrlPrefix | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
6 | |
100.00% |
1 / 1 |
render | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Drupal\visitors\Plugin\views\field; |
4 | |
5 | use Drupal\views\Attribute\ViewsField; |
6 | use Drupal\views\Plugin\views\field\FieldPluginBase; |
7 | |
8 | /** |
9 | * Field handler to display the hour (server) of the visit. |
10 | * |
11 | * @ingroup views_field_handlers |
12 | */ |
13 | #[ViewsField("visitors_url_prefix")] |
14 | final class UrlPrefix extends FieldPluginBase { |
15 | |
16 | /** |
17 | * {@inheritdoc} |
18 | */ |
19 | public function render($values) { |
20 | $prefix = ''; |
21 | $value = (int) $this->getValue($values); |
22 | switch ($value) { |
23 | case 3: |
24 | $prefix = 'https://www.'; |
25 | break; |
26 | |
27 | case 2: |
28 | $prefix = 'https://'; |
29 | break; |
30 | |
31 | case 1: |
32 | $prefix = 'http://www.'; |
33 | break; |
34 | |
35 | case 0: |
36 | default: |
37 | $prefix = 'http://'; |
38 | break; |
39 | } |
40 | |
41 | return $prefix; |
42 | } |
43 | |
44 | } |