EntityReferenceFieldFormatter::getFieldValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\entity_embed\Plugin\entity_embed\EntityEmbedDisplay;
4
5
use Drupal\entity_embed\EntityEmbedDisplay\FieldFormatterEntityEmbedDisplayBase;
6
7
/**
8
 * Entity Embed Display reusing entity reference field formatters.
9
 *
10
 * @see \Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayInterface
11
 *
12
 * @EntityEmbedDisplay(
13
 *   id = "entity_reference",
14
 *   label = @Translation("Entity Reference"),
15
 *   deriver = "Drupal\entity_embed\Plugin\Derivative\FieldFormatterDeriver",
16
 *   field_type = "entity_reference"
17
 * )
18
 */
19
class EntityReferenceFieldFormatter extends FieldFormatterEntityEmbedDisplayBase {
20
21
  /**
22
   * {@inheritdoc}
23
   */
24
  public function getFieldDefinition() {
25
    if (!isset($this->fieldDefinition)) {
26
      $this->fieldDefinition = parent::getFieldDefinition();
27
      $this->fieldDefinition->setSetting('target_type', $this->getEntityTypeFromContext());
28
    }
29
    return $this->fieldDefinition;
30
  }
31
32
  /**
33
   * {@inheritdoc}
34
   */
35
  public function getFieldValue() {
36
    return array('target_id' => $this->getContextValue('entity')->id());
37
  }
38
39
}
40