Commit fd6e1400 authored by Berdir's avatar Berdir Committed by slashrsm

Issue #2774425 by Berdir: ImageFieldFormatter::isValidImage() can be extremely...

Issue #2774425 by Berdir: ImageFieldFormatter::isValidImage() can be extremely slow for large images or on slow filesystems.
parent b5c62bb8
......@@ -108,7 +108,10 @@ class ImageFieldFormatter extends FileFieldFormatter {
// @see \Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayBase::getEntityFromContext()
/** @var \Drupal\file\FileInterface $entity */
if ($entity = $this->getEntityFromContext()) {
$access = AccessResult::allowedIf($this->imageFactory->get($entity->getFileUri())->isValid())
// Loading large files is slow, make sure it is an image mime type before
// doing that.
list($type, ) = explode('/', $entity->getMimeType(), 2);
$access = AccessResult::allowedIf($type == 'image' && $this->imageFactory->get($entity->getFileUri())->isValid())
// See the above @todo, this is the best we can do for now.
->addCacheableDependency($entity);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment