Skip to content

Commit bd31691

Browse files
committed
Migrated graphql_link to graphql_core.
1 parent 6b97f39 commit bd31691

14 files changed

Lines changed: 161 additions & 41 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Drupal\graphql_core\Plugin\Deriver\Fields;
4+
5+
use Drupal\Core\Field\FieldStorageDefinitionInterface;
6+
use Drupal\graphql_core\Plugin\Deriver\EntityFieldDeriverWithTypeMapping;
7+
use Drupal\graphql_core\Plugin\GraphQL\Types\Entity\EntityFieldType;
8+
9+
/**
10+
* Attach new properties to field types.
11+
*/
12+
class EntityFieldPropertyDeriver extends EntityFieldDeriverWithTypeMapping {
13+
14+
protected function getDerivativeDefinitionsFromFieldDefinition(
15+
$entityTypeId,
16+
FieldStorageDefinitionInterface $fieldDefinition,
17+
array $basePluginDefinition
18+
) {
19+
20+
$derivatives = [];
21+
22+
if (isset($basePluginDefinition['field_types']) && in_array($fieldDefinition->getType(), $basePluginDefinition['field_types'])) {
23+
$fieldName = $fieldDefinition->getName();
24+
$derivatives["$entityTypeId-$fieldName-" . $basePluginDefinition['id']] = [
25+
'parents' => [EntityFieldType::getId($entityTypeId, $fieldName)]
26+
] + $basePluginDefinition;
27+
}
28+
29+
return $derivatives;
30+
}
31+
32+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Links;
4+
5+
use Drupal\Component\Utility\NestedArray;
6+
use Drupal\link\LinkItemInterface;
7+
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
8+
use Youshido\GraphQL\Execution\ResolveInfo;
9+
10+
/**
11+
* Retrieve specific attributes of a menu link.
12+
*
13+
* @GraphQLField(
14+
* id = "link_item_attribute",
15+
* secure = true,
16+
* name = "attribute",
17+
* type = "String",
18+
* nullable = true,
19+
* arguments = {
20+
* "key" = "String"
21+
* },
22+
* deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityFieldPropertyDeriver",
23+
* field_types = {"link"}
24+
* )
25+
*/
26+
class LinkAttribute extends FieldPluginBase {
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
protected function resolveValues($value, array $args, ResolveInfo $info) {
32+
if ($value instanceof LinkItemInterface) {
33+
$options = $value->getUrl()->getOptions();
34+
yield NestedArray::getValue($options, ['attributes', $args['key']]);
35+
}
36+
}
37+
38+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Links;
4+
5+
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
6+
use Drupal\link\LinkItemInterface;
7+
use Youshido\GraphQL\Execution\ResolveInfo;
8+
9+
/**
10+
* Retrieve a link fields route object.
11+
*
12+
* @GraphQLField(
13+
* id = "link_item_url",
14+
* secure = true,
15+
* name = "url",
16+
* type = "Url",
17+
* deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityFieldPropertyDeriver",
18+
* field_types = {"link"}
19+
* )
20+
*/
21+
class LinkUrl extends FieldPluginBase {
22+
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function resolveValues($value, array $args, ResolveInfo $info) {
27+
if ($value instanceof LinkItemInterface) {
28+
yield $value->getUrl();
29+
}
30+
}
31+
32+
}

modules/graphql_core/tests/queries/raw_field_values.gql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ query ($path: String!) {
3737
fieldLink {
3838
title
3939
uri
40+
target:attribute(key: "_target")
41+
url {
42+
... on InternalUrl {
43+
internal:path
44+
}
45+
... on ExternalUrl {
46+
external:path
47+
}
48+
}
49+
4050
}
4151
fieldInteger {
4252
value

modules/graphql_core/tests/src/Kernel/Entity/EntityFieldValueTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,15 @@ public function nodeValuesProvider() {
137137
'field_text' => ['a', 'b', 'c'],
138138
'field_boolean' => [TRUE, FALSE],
139139
'field_link' => [
140-
['title' => 'Internal link', 'uri' => 'internal:/node/1'],
141-
['title' => 'External link', 'uri' => 'http://drupal.org'],
140+
[
141+
'title' => 'Internal link',
142+
'uri' => 'internal:/node/1',
143+
'options' => ['attributes' => ['_target' => 'blank']],
144+
], [
145+
'title' => 'External link',
146+
'uri' => 'http://drupal.org',
147+
'options' => ['attributes' => ['_target' => 'blank']],
148+
],
142149
],
143150
'field_integer' => [10, -5],
144151
'field_float' => [3.14145, -8.8],
@@ -215,8 +222,8 @@ public function nodeValuesProvider() {
215222
FALSE,
216223
],
217224
'fieldLink' => [
218-
['title' => 'Internal link', 'uri' => 'internal:/node/1'],
219-
['title' => 'External link', 'uri' => 'http://drupal.org'],
225+
['title' => 'Internal link', 'uri' => 'internal:/node/1', 'target' => 'blank', 'url' => ['internal' => '/node/1']],
226+
['title' => 'External link', 'uri' => 'http://drupal.org', 'target' => 'blank', 'url' => ['external' => 'http://drupal.org']],
220227
],
221228
'fieldInteger' => [
222229
10,

modules/graphql_link/graphql_link.info.yml renamed to modules/graphql_legacy/graphql_link/graphql_link.info.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ type: module
33
description: 'Retrieve distinct properties from link fields.'
44
package: GraphQL
55
core: 8.x
6+
hidden: true
67
dependencies:
78
- graphql_content

modules/graphql_link/src/Plugin/Field/FieldFormatter/GraphQLLinkFormatter.php renamed to modules/graphql_legacy/graphql_link/src/Plugin/Field/FieldFormatter/GraphQLLinkFormatter.php

File renamed without changes.

modules/graphql_link/src/Plugin/GraphQL/Fields/Label.php renamed to modules/graphql_legacy/graphql_link/src/Plugin/GraphQL/Fields/Label.php

File renamed without changes.

modules/graphql_link/src/Plugin/GraphQL/Fields/LinkAttribute.php renamed to modules/graphql_legacy/graphql_link/src/Plugin/GraphQL/Fields/LinkAttribute.php

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
<?php
2-
3-
namespace Drupal\graphql_link\Plugin\GraphQL\Fields;
4-
5-
use Drupal\Component\Utility\NestedArray;
6-
use Drupal\link\LinkItemInterface;
7-
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
8-
use Youshido\GraphQL\Execution\ResolveInfo;
9-
10-
/**
11-
* Retrieve specific attributes of a menu link.
12-
*
13-
* @GraphQLField(
14-
* id = "link_item_attribute",
15-
* secure = true,
16-
* name = "attribute",
17-
* type = "String",
18-
* parents = {"LinkItem"},
19-
* nullable = true,
20-
* arguments = {
21-
* "key" = "String"
22-
* }
23-
* )
24-
*/
25-
class LinkAttribute extends FieldPluginBase {
26-
27-
/**
28-
* {@inheritdoc}
29-
*/
30-
protected function resolveValues($value, array $args, ResolveInfo $info) {
31-
if ($value instanceof LinkItemInterface) {
32-
$options = $value->getUrl()->getOptions();
33-
yield NestedArray::getValue($options, ['attributes', $args['key']]);
34-
}
35-
}
36-
37-
}
1+
<?php
2+
3+
namespace Drupal\graphql_link\Plugin\GraphQL\Fields;
4+
5+
use Drupal\Component\Utility\NestedArray;
6+
use Drupal\link\LinkItemInterface;
7+
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
8+
use Youshido\GraphQL\Execution\ResolveInfo;
9+
10+
/**
11+
* Retrieve specific attributes of a menu link.
12+
*
13+
* @GraphQLField(
14+
* id = "link_item_attribute",
15+
* secure = true,
16+
* name = "attribute",
17+
* type = "String",
18+
* nullable = true,
19+
* arguments = {
20+
* "key" = "String"
21+
* },
22+
* parents = {"LinkItem"}
23+
* )
24+
*/
25+
class LinkAttribute extends FieldPluginBase {
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
protected function resolveValues($value, array $args, ResolveInfo $info) {
31+
if ($value instanceof LinkItemInterface) {
32+
$options = $value->getUrl()->getOptions();
33+
yield NestedArray::getValue($options, ['attributes', $args['key']]);
34+
}
35+
}
36+
37+
}

modules/graphql_link/src/Plugin/GraphQL/Fields/LinkField.php renamed to modules/graphql_legacy/graphql_link/src/Plugin/GraphQL/Fields/LinkField.php

File renamed without changes.

0 commit comments

Comments
 (0)