Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ExternalIdentifierDefaultFormatter | |
0.00% |
0 / 26 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
defaultSettings | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
settingsForm | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
settingsSummary | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
viewElements | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
20 |
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\Core\Form\FormStateInterface; |
8 | |
9 | /** |
10 | * Plugin implementation of the 'crm_external_identifier_default' formatter. |
11 | * |
12 | * @FieldFormatter( |
13 | * id = "crm_external_identifier_default", |
14 | * label = @Translation("Default"), |
15 | * field_types = {"crm_external_identifier"} |
16 | * ) |
17 | */ |
18 | class ExternalIdentifierDefaultFormatter extends FormatterBase { |
19 | |
20 | /** |
21 | * {@inheritdoc} |
22 | */ |
23 | public static function defaultSettings() { |
24 | return ['foo' => 'bar'] + parent::defaultSettings(); |
25 | } |
26 | |
27 | /** |
28 | * {@inheritdoc} |
29 | */ |
30 | public function settingsForm(array $form, FormStateInterface $form_state) { |
31 | $settings = $this->getSettings(); |
32 | $element['foo'] = [ |
33 | '#type' => 'textfield', |
34 | '#title' => $this->t('Foo'), |
35 | '#default_value' => $settings['foo'], |
36 | ]; |
37 | return $element; |
38 | } |
39 | |
40 | /** |
41 | * {@inheritdoc} |
42 | */ |
43 | public function settingsSummary() { |
44 | $settings = $this->getSettings(); |
45 | $summary[] = $this->t('Foo: @foo', ['@foo' => $settings['foo']]); |
46 | return $summary; |
47 | } |
48 | |
49 | /** |
50 | * {@inheritdoc} |
51 | */ |
52 | public function viewElements(FieldItemListInterface $items, $langcode) { |
53 | $element = []; |
54 | |
55 | foreach ($items as $delta => $item) { |
56 | |
57 | if ($item->source) { |
58 | $element[$delta]['source'] = [ |
59 | '#type' => 'item', |
60 | '#title' => $this->t('Source'), |
61 | '#markup' => $item->source, |
62 | ]; |
63 | } |
64 | |
65 | if ($item->identifier) { |
66 | $element[$delta]['identifier'] = [ |
67 | '#type' => 'item', |
68 | '#title' => $this->t('Identifier'), |
69 | '#markup' => $item->identifier, |
70 | ]; |
71 | } |
72 | |
73 | } |
74 | |
75 | return $element; |
76 | } |
77 | |
78 | } |