You are here

class EntityReferenceFieldItemNormalizer in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer

Adds the file URI to embedded file entities.

Hierarchy

Expanded class hierarchy of EntityReferenceFieldItemNormalizer

1 file declares its use of EntityReferenceFieldItemNormalizer
EntityReferenceFieldItemNormalizerTest.php in core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php
Contains \Drupal\Tests\serialization\Unit\Normalizer\EntityReferenceFieldItemNormalizerTest.
1 string reference to 'EntityReferenceFieldItemNormalizer'
serialization.services.yml in core/modules/serialization/serialization.services.yml
core/modules/serialization/serialization.services.yml
1 service uses EntityReferenceFieldItemNormalizer
serializer.normalizer.entity_reference_field_item in core/modules/serialization/serialization.services.yml
Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer

File

core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php, line 15
Contains \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer.

Namespace

Drupal\serialization\Normalizer
View source
class EntityReferenceFieldItemNormalizer extends ComplexDataNormalizer {

  /**
   * The interface or class that this Normalizer supports.
   *
   * @var string
   */
  protected $supportedInterfaceOrClass = EntityReferenceItem::class;

  /**
   * {@inheritdoc}
   */
  public function normalize($field_item, $format = NULL, array $context = []) {
    $values = parent::normalize($field_item, $format, $context);

    // Add a 'url' value if there is a reference and a canonical URL. Hard code
    // 'canonical' here as config entities override the default $rel parameter
    // value to 'edit-form.

    /** @var \Drupal\Core\Entity\EntityInterface $entity */
    if (($entity = $field_item
      ->get('entity')
      ->getValue()) && ($url = $entity
      ->url('canonical'))) {
      $values['url'] = $url;
    }
    return $values;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityReferenceFieldItemNormalizer::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. Overrides ComplexDataNormalizer::$supportedInterfaceOrClass
EntityReferenceFieldItemNormalizer::normalize public function Normalizes an object into a set of arrays/scalars. Overrides ComplexDataNormalizer::normalize
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer.
NormalizerBase::supportsDenormalization public function Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() 1
NormalizerBase::supportsNormalization public function Checks whether the given class is supported for normalization by this normalizer. Overrides NormalizerInterface::supportsNormalization 1
SerializerAwareNormalizer::$serializer protected property
SerializerAwareNormalizer::setSerializer public function Sets the owning Serializer object. Overrides SerializerAwareInterface::setSerializer