From 76313507aaf4f5444fb1b32296bba28d797d750c Mon Sep 17 00:00:00 2001 From: matx132 Date: Mon, 25 Nov 2024 14:58:36 +0100 Subject: [PATCH] IBX-7603: Added missing subfield for ezurl --- .../Resources/config/default_settings.yaml | 1 + .../Resources/config/graphql/Field.types.yaml | 13 +++++ .../Resources/config/services/schema.yaml | 6 +++ .../UrlFieldDefinitionMapper.php | 53 +++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 src/lib/Schema/Domain/Content/Mapper/FieldDefinition/UrlFieldDefinitionMapper.php diff --git a/src/bundle/Resources/config/default_settings.yaml b/src/bundle/Resources/config/default_settings.yaml index 65aef8c..b2de900 100644 --- a/src/bundle/Resources/config/default_settings.yaml +++ b/src/bundle/Resources/config/default_settings.yaml @@ -1,4 +1,5 @@ parameters: + ibexa.graphql.schema.should.extend.ezurl: false ibexa.graphql.schema.content.field_name.override: id: id_ ibexa.graphql.schema.content.mapping.field_definition_type: diff --git a/src/bundle/Resources/config/graphql/Field.types.yaml b/src/bundle/Resources/config/graphql/Field.types.yaml index 39b96d3..f413872 100644 --- a/src/bundle/Resources/config/graphql/Field.types.yaml +++ b/src/bundle/Resources/config/graphql/Field.types.yaml @@ -266,3 +266,16 @@ SelectionFieldValue: type: "String" description: "String representation of the value" resolve: "@=value" + +UrlFieldValue: + type: object + config: + fields: + link: + type: String + description: "The link's URL" + resolve: "@=value.link" + text: + type: String + description: "The link's name or description" + resolve: "@=value.text" diff --git a/src/bundle/Resources/config/services/schema.yaml b/src/bundle/Resources/config/services/schema.yaml index b720aff..14741e4 100644 --- a/src/bundle/Resources/config/services/schema.yaml +++ b/src/bundle/Resources/config/services/schema.yaml @@ -49,6 +49,12 @@ services: arguments: $innerMapper: '@Ibexa\GraphQL\Schema\Domain\Content\Mapper\FieldDefinition\SelectionFieldDefinitionMapper.inner' + Ibexa\GraphQL\Schema\Domain\Content\Mapper\FieldDefinition\UrlFieldDefinitionMapper: + decorates: Ibexa\Contracts\GraphQL\Schema\Domain\Content\Mapper\FieldDefinition\FieldDefinitionMapper + arguments: + $innerMapper: '@Ibexa\GraphQL\Schema\Domain\Content\Mapper\FieldDefinition\UrlFieldDefinitionMapper.inner' + $shouldExtendUrlInputType: '%ibexa.graphql.schema.should.extend.ezurl%' + Ibexa\GraphQL\Schema\Domain\Content\Worker\FieldDefinition\AddFieldValueToDomainContent: ~ Ibexa\GraphQL\Schema\Domain\Content\Worker\ContentType\AddItemOfTypeConnectionToGroup: ~ diff --git a/src/lib/Schema/Domain/Content/Mapper/FieldDefinition/UrlFieldDefinitionMapper.php b/src/lib/Schema/Domain/Content/Mapper/FieldDefinition/UrlFieldDefinitionMapper.php new file mode 100644 index 0000000..fb37b63 --- /dev/null +++ b/src/lib/Schema/Domain/Content/Mapper/FieldDefinition/UrlFieldDefinitionMapper.php @@ -0,0 +1,53 @@ +shouldExtendUrlInputType = $shouldExtendUrlInputType; + } + + public function mapToFieldValueType(FieldDefinition $fieldDefinition): string + { + $type = parent::mapToFieldValueType($fieldDefinition); + if (!$this->canMap($fieldDefinition)) { + return $type; + } + + if ($this->shouldExtendUrlInputType) { + $type = 'UrlFieldValue'; + } else { + @trigger_error( + 'The return type `string` for the URL field has been deprecated since version 4.6 ' . + '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; + } + + protected function getFieldTypeIdentifier(): string + { + return self::FIELD_TYPE_IDENTIFIER; + } +}