Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
CRMTelephoneTableFormatter | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
viewElements | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
30 |
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\CRMTelephoneItem; |
8 | |
9 | /** |
10 | * Plugin implementation of the 'crm_telephone_table' formatter. |
11 | * |
12 | * @FieldFormatter( |
13 | * id = "crm_telephone_table", |
14 | * label = @Translation("Table"), |
15 | * field_types = {"crm_telephone"} |
16 | * ) |
17 | */ |
18 | class CRMTelephoneTableFormatter extends FormatterBase { |
19 | |
20 | /** |
21 | * {@inheritdoc} |
22 | */ |
23 | public function viewElements(FieldItemListInterface $items, $langcode) { |
24 | |
25 | $header[] = '#'; |
26 | $header[] = $this->t('Phone'); |
27 | $header[] = $this->t('Extension'); |
28 | $header[] = $this->t('Type'); |
29 | $header[] = $this->t('Location'); |
30 | $header[] = $this->t('Primary'); |
31 | $header[] = $this->t('Mobile Provider'); |
32 | |
33 | $table = [ |
34 | '#type' => 'table', |
35 | '#header' => $header, |
36 | ]; |
37 | |
38 | foreach ($items as $delta => $item) { |
39 | $row = []; |
40 | |
41 | $row[]['#markup'] = $delta + 1; |
42 | |
43 | $row[]['#markup'] = $item->phone; |
44 | |
45 | $row[]['#markup'] = $item->phone_ext; |
46 | |
47 | if ($item->type) { |
48 | $allowed_values = CRMTelephoneItem::allowedTypeValues(); |
49 | $row[]['#markup'] = $allowed_values[$item->type]; |
50 | } |
51 | else { |
52 | $row[]['#markup'] = ''; |
53 | } |
54 | |
55 | $row[]['#markup'] = $item->location_id; |
56 | |
57 | $row[]['#markup'] = $item->primary ? $this->t('Yes') : $this->t('No'); |
58 | |
59 | if ($item->mobile_provider_id) { |
60 | $allowed_values = CRMTelephoneItem::allowedMobileProviderValues(); |
61 | $row[]['#markup'] = $allowed_values[$item->mobile_provider_id]; |
62 | } |
63 | else { |
64 | $row[]['#markup'] = ''; |
65 | } |
66 | |
67 | $table[$delta] = $row; |
68 | } |
69 | |
70 | return [$table]; |
71 | } |
72 | |
73 | } |