You are here

protected function LinkCollectionNormalizer::decorationApplies in Consumer Image Styles 8.3

Same name and namespace in other branches
  1. 4.x src/Normalizer/LinkCollectionNormalizer.php \Drupal\consumer_image_styles\Normalizer\LinkCollectionNormalizer::decorationApplies()

Whether this decorator applies to the current data.

Parameters

\Drupal\jsonapi\JsonApiResource\LinkCollection $link_collection: The link collection to be normalized.

Return value

bool TRUE if the link collection belongs to an image file resource object, FALSE otherwise.

1 call to LinkCollectionNormalizer::decorationApplies()
LinkCollectionNormalizer::normalize in src/Normalizer/LinkCollectionNormalizer.php
Normalizes an object into a set of arrays/scalars.

File

src/Normalizer/LinkCollectionNormalizer.php, line 122

Class

LinkCollectionNormalizer
Custom normalizer that add the derivatives to image entities.

Namespace

Drupal\consumer_image_styles\Normalizer

Code

protected function decorationApplies(LinkCollection $link_collection) {
  $link_context = $link_collection
    ->getContext();
  if (!$link_context instanceof ResourceObject) {
    return FALSE;
  }
  $resource_type = $link_context
    ->getResourceType();
  if ($resource_type
    ->getEntityTypeId() !== 'file') {
    return FALSE;
  }
  return $this->imageFactory
    ->get($link_context
    ->getField($resource_type
    ->getPublicName('uri'))->value)
    ->isValid();
}