Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-6602: Used Content::getThumbnail directly for obtaining thumbnails #56

Merged
merged 4 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' => '',
konradoboza marked this conversation as resolved.
Show resolved Hide resolved
];
}
}
Loading