diff --git a/src/GraphQL/AssetType/AssetType.php b/src/GraphQL/AssetType/AssetType.php index cd53fd47..034bb6f1 100644 --- a/src/GraphQL/AssetType/AssetType.php +++ b/src/GraphQL/AssetType/AssetType.php @@ -98,7 +98,8 @@ public function build(&$config) 'type' => Type::string(), 'args' => [ 'thumbnail' => ['type' => Type::string()], - 'format' => ['type' => Type::string()] + 'format' => ['type' => Type::string()], + 'deferred' => ['type' => Type::boolean(), 'defaultValue' => true], ], 'resolve' => [$resolver, 'resolvePath'], ], diff --git a/src/GraphQL/FieldHelper/AssetFieldHelper.php b/src/GraphQL/FieldHelper/AssetFieldHelper.php index dcb335b1..bbabd2e0 100644 --- a/src/GraphQL/FieldHelper/AssetFieldHelper.php +++ b/src/GraphQL/FieldHelper/AssetFieldHelper.php @@ -41,14 +41,14 @@ public function getVideoThumbnail(Asset\Video $asset, string | Video\Thumbnail\C return null; } - public function getImageDocumentThumbnail(Asset $asset, string | Image\Thumbnail\Config $thumbNailConfig, string $thumbNailFormat = null): mixed + public function getImageDocumentThumbnail(Asset $asset, string | Image\Thumbnail\Config $thumbNailConfig, string $thumbNailFormat = null, $deferred = false): mixed { $thumb = null; if ($asset instanceof Asset\Document || $asset instanceof Asset\Video) { $thumb = $asset->getImageThumbnail($thumbNailConfig); } elseif ($asset instanceof Asset\Image) { - $thumb = $asset->getThumbnail($thumbNailConfig, false); + $thumb = $asset->getThumbnail($thumbNailConfig, $deferred); } if (isset($thumb, $thumbNailFormat) && method_exists($thumb, 'getAsFormat') && !($asset instanceof Asset\Video)) { $thumb = $thumb->getAsFormat($thumbNailFormat); @@ -57,12 +57,20 @@ public function getImageDocumentThumbnail(Asset $asset, string | Image\Thumbnail return $thumb; } - public function getAssetThumbnail(Asset $asset, string | Image\Thumbnail\Config | Video\Thumbnail\Config $thumbNailConfig, string $thumbNailFormat = null): mixed + /** + * @param \Pimcore\Model\Asset $asset + * @param string|\Pimcore\Model\Asset\Image\Thumbnail\Config|\Pimcore\Model\Asset\Video\Thumbnail\Config $thumbNailConfig + * @param string|null $thumbNailFormat + * @param bool $deferred Taken in account _if viable_. + * + * @return mixed + */ + public function getAssetThumbnail(Asset $asset, string | Image\Thumbnail\Config | Video\Thumbnail\Config $thumbNailConfig, string $thumbNailFormat = null, bool $deferred = false): mixed { if (($asset instanceof Asset\Video) && (is_string($thumbNailConfig) || $thumbNailConfig instanceof Video\Thumbnail\Config)) { return $this->getVideoThumbnail($asset, $thumbNailConfig, $thumbNailFormat); } else { - return $this->getImageDocumentThumbnail($asset, $thumbNailConfig, $thumbNailFormat); + return $this->getImageDocumentThumbnail($asset, $thumbNailConfig, $thumbNailFormat, $deferred); } } diff --git a/src/GraphQL/Resolver/AssetType.php b/src/GraphQL/Resolver/AssetType.php index 62b8a12f..886cc00f 100644 --- a/src/GraphQL/Resolver/AssetType.php +++ b/src/GraphQL/Resolver/AssetType.php @@ -147,23 +147,13 @@ public function resolvePath($value = null, $args = [], $context = [], ResolveInf if (!isset($thumbNailConfig)) { return $asset->getFullPath(); } - // @TODO: check if this still possible with the new metohd - // before we had: - /* - * if ($asset instanceof Asset\Image) { - * return isset($args['thumbnail']) ? $asset->getThumbnail($args['thumbnail'], $deferredThumbnail) : $asset->getFullPath(); - * } - */ - // get thumbnails with the "deferred" option as we don't need the data itself - // only the URL and the generation of the thumbnail should happen later - // which is done during request the image and could be parallelized from the browser - $deferredThumbnail = false; - if (!$resolveInfo || $resolveInfo->fieldName !== 'data') { - $deferredThumbnail = true; - } - - return $assetFieldHelper->getAssetThumbnail($asset, $thumbNailConfig, $thumbNailFormat); + return $assetFieldHelper->getAssetThumbnail( + $asset, + $thumbNailConfig, + $thumbNailFormat, + !empty($args['deferred']) + ); } return Service::resolveCachedValue($value, $resolveInfo);