Skip to content

Commit

Permalink
IBX-7603: A new flag has been introduced that generates a different s…
Browse files Browse the repository at this point in the history
…chema for ezurl
  • Loading branch information
mateuszdebinski committed Jul 1, 2024
1 parent f616e1f commit b278248
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"bdunogier/ezplatform-graphql-bundle": "self.version"
},
"require": {
"php": "^7.3 || ^8.0",
"php": "^7.4 || ^8.0",
"ext-dom": "*",
"ezsystems/ezplatform-kernel": "^1.3@dev",
"ezsystems/ezplatform-admin-ui": "^2.0@dev",
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/default_settings.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
parameters:
ibexa.graphql.schema.should.extend.ezurl: true
ezplatform_graphql.schema.content.field_name.override:
id: id_
ezplatform_graphql.schema.content.mapping.field_definition_type:
Expand Down Expand Up @@ -81,5 +82,4 @@ parameters:
definition_type: TextBlockFieldDefinition
value_type: String
ezurl:
value_type: UrlFieldValue
input_type: UrlFieldInput
4 changes: 2 additions & 2 deletions src/Resources/config/graphql/FieldValueInput.types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ UrlFieldInput:
config:
fields:
link:
type: String!
type: String
description: "The link's URL"
text:
type: String
type: String!
description: "The link's name or description"

MapLocationFieldInput:
Expand Down
6 changes: 6 additions & 0 deletions src/Resources/config/services/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ services:
arguments:
$innerMapper: '@EzSystems\EzPlatformGraphQL\Schema\Domain\Content\Mapper\FieldDefinition\SelectionFieldDefinitionMapper.inner'

Ibexa\GraphQL\Schema\Domain\Content\Mapper\FieldDefinition\UrlFieldDefinitionMapper:
decorates: EzSystems\EzPlatformGraphQL\Schema\Domain\Content\Mapper\FieldDefinition\FieldDefinitionMapper
arguments:
$innerMapper: '@Ibexa\GraphQL\Schema\Domain\Content\Mapper\FieldDefinition\UrlFieldDefinitionMapper.inner'
$shouldExtendUrlInputType: '%ibexa.graphql.schema.should.extend.ezurl%'

EzSystems\EzPlatformGraphQL\Schema\Domain\Content\Worker\ContentType\AddContentOfTypeConnectionToDomainGroup: ~

EzSystems\EzPlatformGraphQL\Schema\Domain\Content\Worker\ContentType\AddContentTypeToContentTypeIdentifierList: ~
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace Ibexa\GraphQL\Schema\Domain\Content\Mapper\FieldDefinition;

use EzSystems\EzPlatformGraphQL\Schema\Domain\Content\Mapper\FieldDefinition\FieldDefinitionMapper;
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition;

class UrlFieldDefinitionMapper implements FieldDefinitionMapper
{
private const FIELD_TYPE_IDENTIFIER = 'ezurl';
private FieldDefinitionMapper $innerMapper;
private bool $shouldExtendUrlInputType;

public function __construct(FieldDefinitionMapper $innerMapper, bool $shouldExtendUrlInputType)
{
$this->innerMapper = $innerMapper;
$this->shouldExtendUrlInputType = $shouldExtendUrlInputType;
}

public function mapToFieldDefinitionType(FieldDefinition $fieldDefinition): string
{
return $this->innerMapper->mapToFieldDefinitionType($fieldDefinition);
}

public function mapToFieldValueType(FieldDefinition $fieldDefinition): string
{
$type = $this->innerMapper->mapToFieldValueType($fieldDefinition);
if ($fieldDefinition->fieldTypeIdentifier === self::FIELD_TYPE_IDENTIFIER) {
if ($this->shouldExtendUrlInputType) {
$type = 'UrlFieldValue';
} else {
@trigger_error(
'The return type `string` for the URL field has been deprecated since version 3.3 ' .
'and will be removed in version 5.0. To start receiving `UrlFieldInput` instead of the deprecated ' .
'`string`, set the parameter `ibexa.graphql.schema.should.extend.ezurl` to `true`.',
E_USER_DEPRECATED
);
}
}

return $type;
}

public function mapToFieldValueResolver(FieldDefinition $fieldDefinition): string
{
return $this->innerMapper->mapToFieldValueResolver($fieldDefinition);
}

public function mapToFieldValueInputType(ContentType $contentType, FieldDefinition $fieldDefinition): ?string
{
return $this->innerMapper->mapToFieldValueInputType($contentType, $fieldDefinition);
}

public function mapToFieldValueArgsBuilder(FieldDefinition $fieldDefinition): ?string
{
return $this->innerMapper->mapToFieldValueArgsBuilder($fieldDefinition);
}
}

0 comments on commit b278248

Please sign in to comment.