Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
PrimaryEntityReferenceFormatterHooks
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 fieldFormatterInfoAlter
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace Drupal\primary_entity_reference\Hook;
6
7use Drupal\Core\Hook\Attribute\Hook;
8
9/**
10 * Field formatter hook implementations for primary_entity_reference.
11 */
12class PrimaryEntityReferenceFormatterHooks {
13
14  /**
15   * Implements hook_field_formatter_info_alter().
16   */
17  #[Hook('field_formatter_info_alter')]
18  public function fieldFormatterInfoAlter(array &$info): void {
19    foreach ($info as $key => $formatter_info) {
20      if (in_array('entity_reference', $formatter_info['field_types'], TRUE)) {
21        $info[$key]['field_types'][] = 'primary_entity_reference';
22      }
23    }
24  }
25
26}