You are here

public function EntityReferenceNormalizer::supportsNormalization in Commerce Cart API 8

Overrides NormalizerBase::supportsNormalization

File

src/Normalizer/EntityReferenceNormalizer.php, line 48

Class

EntityReferenceNormalizer
Expands entity reference field values to their referenced entity.

Namespace

Drupal\commerce_cart_api\Normalizer

Code

public function supportsNormalization($data, $format = NULL) {
  $supported = parent::supportsNormalization($data, $format);
  if ($supported) {
    $route = $this->routeMatch
      ->getRouteObject();

    /** @var \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem $data */
    $name = $data
      ->getFieldDefinition()
      ->getName();
    return $route && in_array($name, $this
      ->getSupportedFields(), TRUE) && $route
      ->hasRequirement('_cart_api');
  }
  return FALSE;
}