Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ExternalIdentifierTableFormatter | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| viewElements | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 | |||
| 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 | |
| 8 | /** |
| 9 | * Plugin implementation of the 'crm_external_identifier_table' formatter. |
| 10 | * |
| 11 | * @FieldFormatter( |
| 12 | * id = "crm_external_identifier_table", |
| 13 | * label = @Translation("Table"), |
| 14 | * field_types = {"crm_external_identifier"} |
| 15 | * ) |
| 16 | */ |
| 17 | class ExternalIdentifierTableFormatter extends FormatterBase { |
| 18 | |
| 19 | /** |
| 20 | * {@inheritdoc} |
| 21 | */ |
| 22 | public function viewElements(FieldItemListInterface $items, $langcode) { |
| 23 | |
| 24 | $header[] = '#'; |
| 25 | $header[] = $this->t('Source'); |
| 26 | $header[] = $this->t('Identifier'); |
| 27 | |
| 28 | $table = [ |
| 29 | '#type' => 'table', |
| 30 | '#header' => $header, |
| 31 | ]; |
| 32 | |
| 33 | foreach ($items as $delta => $item) { |
| 34 | $row = []; |
| 35 | |
| 36 | $row[]['#markup'] = $delta + 1; |
| 37 | |
| 38 | $row[]['#markup'] = $item->source; |
| 39 | |
| 40 | $row[]['#markup'] = $item->identifier; |
| 41 | |
| 42 | $table[$delta] = $row; |
| 43 | } |
| 44 | |
| 45 | return [$table]; |
| 46 | } |
| 47 | |
| 48 | } |