Skip to content

Commit

Permalink
IBX-6602: Used Content::getThumbnail directly for obtaining thumbnails (
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniTou authored Sep 29, 2023
1 parent 0d5bbba commit 5aaf673
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 8 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"ibexa/http-cache": "~4.5.0@dev",
"overblog/graphiql-bundle": "^0.2",
"phpspec/phpspec": "^7.1",
"friendsofphp/php-cs-fixer": "^3.0",
"ibexa/code-style": "^1.0",
"ibexa/code-style": "~1.2.0",
"mikey179/vfsstream": "^1.6"
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/Resources/config/graphql/ContentType.types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ContentTypeGroup:
resolve: "@=resolver('UserById', [value.modifierId])"
contentTypes:
type: "[ContentType]"
resolve: "@=resolver('ContentTypesFromGroup', {'groupId': value.id})"
resolve: "@=query('ContentTypesFromGroup', {'groupId': value.id})"
groups:
type: "[ContentTypeGroup]"

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ AbstractDomainContent:
resolve: "@=resolver('MainUrlAlias', [value])"
_thumbnail:
type: Thumbnail
resolve: "@=resolver('ContentThumbnail', [value])"
resolve: "@=query('Thumbnail', value.getThumbnail())"

UntypedContent:
type: object
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/Resources/config/graphql/Item.types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ AbstractItem:
resolve: "@=resolver('ItemUrlAlias', [value])"
_thumbnail:
type: Thumbnail
resolve: "@=resolver('ContentThumbnail', [value.getContent()])"
resolve: "@=query('Thumbnail', value.getContent().getThumbnail())"

UntypedItem:
type: object
Expand Down
9 changes: 6 additions & 3 deletions src/bundle/Resources/config/graphql/User.types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ User:
resolve: "@=value.contentInfo.name"
content:
type: "UserItem"
resolve: "@=value"
resolve: "@=query('Item', {id: value.id})"
version:
type: "Version"
description: "Current version metadata"
Expand All @@ -23,6 +23,9 @@ User:
groups:
type: "[UserGroup]"
resolve: "@=resolver('UserGroupsByUserId', [value.id])"
thumbnail:
type: Thumbnail
resolve: "@=query('Thumbnail', value.getThumbnail())"

UserGroup:
type: object
Expand All @@ -35,9 +38,9 @@ UserGroup:
type: "String"
resolve: "@=value.contentInfo.name"
content:
description: "The User content item"
description: "The User Group content item"
type: "UserGroupItem"
resolve: "@=value"
resolve: "@=query('Item', {id: value.id})"
version:
type: "Version"
description: "Current version"
Expand Down
4 changes: 4 additions & 0 deletions src/bundle/Resources/config/services/resolvers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ services:
arguments:
$thumbnailStrategy: '@Ibexa\Core\Repository\Strategy\ContentThumbnail\ThumbnailChainStrategy'

Ibexa\GraphQL\Resolver\ThumbnailResolver:
tags:
- { name: overblog_graphql.resolver, alias: "Thumbnail", method: "resolveThumbnail" }

Ibexa\GraphQL\Mutation\Authentication:
arguments:
$authenticator: '@?ibexa.rest.session_authenticator'
Expand Down
32 changes: 32 additions & 0 deletions src/lib/Resolver/ThumbnailResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\GraphQL\Resolver;

use Ibexa\Contracts\Core\Repository\Values\Content\Thumbnail;

final class ThumbnailResolver
{
/**
* @return array|null array with the thumbnail info, or null if no thumbnail could be obtained for that image
*/
public function resolveThumbnail(?Thumbnail $thumbnail): ?array
{
if ($thumbnail === null) {
return null;
}

return [
'uri' => $thumbnail->resource,
'width' => $thumbnail->width,
'height' => $thumbnail->height,
'mimeType' => $thumbnail->mimeType,
'alternativeText' => '',
];
}
}

0 comments on commit 5aaf673

Please sign in to comment.