You are here

protected function LinkCollectionNormalizer::decorationApplies in Consumer Image Styles 4.x

Same name and namespace in other branches
  1. 8.3 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

File

src/Normalizer/LinkCollectionNormalizer.php, line 142

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 in_array(mb_strtolower(pathinfo($link_context
    ->getField($resource_type
    ->getPublicName('uri'))->value, PATHINFO_EXTENSION)), $this->imageFactory
    ->getSupportedExtensions());
}