Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
CRMWebsiteTableFormatter | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
viewElements | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace Drupal\crm_field\Plugin\Field\FieldFormatter; |
4 | |
5 | use Drupal\Core\Field\FieldItemListInterface; |
6 | use Drupal\Core\Field\FormatterBase; |
7 | use Drupal\crm_field\Plugin\Field\FieldType\CRMWebsiteItem; |
8 | |
9 | /** |
10 | * Plugin implementation of the 'crm_website_table' formatter. |
11 | * |
12 | * @FieldFormatter( |
13 | * id = "crm_website_table", |
14 | * label = @Translation("Table"), |
15 | * field_types = {"crm_website"} |
16 | * ) |
17 | */ |
18 | class CRMWebsiteTableFormatter extends FormatterBase { |
19 | |
20 | /** |
21 | * {@inheritdoc} |
22 | */ |
23 | public function viewElements(FieldItemListInterface $items, $langcode) { |
24 | |
25 | $header[] = '#'; |
26 | $header[] = $this->t('Url'); |
27 | $header[] = $this->t('Type'); |
28 | |
29 | $table = [ |
30 | '#type' => 'table', |
31 | '#header' => $header, |
32 | ]; |
33 | |
34 | foreach ($items as $delta => $item) { |
35 | $row = []; |
36 | |
37 | $row[]['#markup'] = $delta + 1; |
38 | |
39 | $row[]['#markup'] = $item->url; |
40 | |
41 | if ($item->type) { |
42 | $allowed_values = CRMWebsiteItem::allowedTypeValues(); |
43 | $row[]['#markup'] = $allowed_values[$item->type]; |
44 | } |
45 | else { |
46 | $row[]['#markup'] = ''; |
47 | } |
48 | |
49 | $table[$delta] = $row; |
50 | } |
51 | |
52 | return [$table]; |
53 | } |
54 | |
55 | } |