File tree 4 files changed +147
-103
lines changed
4 files changed +147
-103
lines changed Original file line number Diff line number Diff line change 22
22
* id = "route_entity",
23
23
* secure = true,
24
24
* name = "entity",
25
- * parents = {"Url "},
25
+ * parents = {"EntityCanonicalUrl "},
26
26
* type = "Entity"
27
27
* )
28
28
*/
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Drupal \graphql_core \Plugin \GraphQL \Types \Entity ;
4
+
5
+ use Drupal \Core \Url ;
6
+ use Drupal \graphql \Plugin \GraphQL \Types \TypePluginBase ;
7
+
8
+ /**
9
+ * GraphQL type for Drupal entity routes.
10
+ *
11
+ * @GraphQLType(
12
+ * id = "entity_canonical_url",
13
+ * name = "EntityCanonicalUrl",
14
+ * interfaces = {"Url"},
15
+ * weight = 1
16
+ * )
17
+ */
18
+ class EntityCanonicalUrl extends TypePluginBase {
19
+
20
+ /**
21
+ * {@inheritdoc}
22
+ */
23
+ public function applies ($ value ) {
24
+ if ($ value instanceof Url && $ value ->isRouted ()) {
25
+ $ parts = explode ('. ' , $ value ->getRouteName ());
26
+ if (count ($ parts ) !== 3 ) {
27
+ return FALSE ;
28
+ }
29
+
30
+ list ($ prefix , $ entityType , $ suffix ) = $ parts ;
31
+ $ parameters = $ value ->getRouteParameters ();
32
+
33
+ if (($ prefix === 'entity ' && $ suffix === 'canonical ' ) && array_key_exists ($ entityType , $ parameters )) {
34
+ return TRUE ;
35
+ }
36
+ }
37
+ return FALSE ;
38
+ }
39
+
40
+ }
Original file line number Diff line number Diff line change 1
1
query ($path : String ! ) {
2
2
route :route (path : $path ) {
3
- node :entity {
4
- image {
5
- alt
6
- title
7
- width
8
- height
9
- entity {
10
- url
11
- }
12
- thumbnailImage :derivative (style : thumbnail ) {
3
+ ... on EntityCanonicalUrl {
4
+ node :entity {
5
+ image {
6
+ alt
7
+ title
13
8
width
14
9
height
15
- url
10
+ entity {
11
+ url
12
+ }
13
+ thumbnailImage :derivative (style : thumbnail ) {
14
+ width
15
+ height
16
+ url
17
+ }
16
18
}
17
19
}
18
20
}
Original file line number Diff line number Diff line change 1
1
query ($path : String ! ) {
2
2
route :route (path : $path ) {
3
- entity {
4
- ... on NodeTest {
5
- nid
6
- vid
7
- langcode {
8
- value
9
- }
10
- type {
11
- targetId
12
- }
13
- uid {
14
- targetId
15
- entity {
16
- name
3
+ ... on EntityCanonicalUrl {
4
+ entity {
5
+ ... on NodeTest {
6
+ nid
7
+ vid
8
+ langcode {
9
+ value
17
10
}
18
- }
19
- title
20
- status
21
- promote
22
- sticky
23
- revisionTranslationAffected
24
- body {
25
- summaryProcessed
26
- summary
27
- processed
28
- format
29
- value
30
- }
31
- fieldText {
32
- value
33
- }
34
- fieldBoolean {
35
- value
36
- }
37
- fieldLink {
38
- title
39
- uri
40
- target :attribute (key : " _target" )
41
- url {
42
- ... on InternalUrl {
43
- internal :path
44
- }
45
- ... on ExternalUrl {
46
- external :path
11
+ type {
12
+ targetId
13
+ }
14
+ uid {
15
+ targetId
16
+ entity {
17
+ name
47
18
}
48
19
}
49
-
50
- }
51
- fieldInteger {
52
- value
53
- }
54
- fieldFloat {
55
- value
56
- }
57
- fieldDecimal {
58
- value
59
- }
60
- fieldDatetime {
61
- value
62
- }
63
- fieldTimestamp {
64
- value
65
- }
66
- fieldEmail {
67
- value
68
- }
69
- fieldString {
70
- value
71
- }
72
- fieldReference {
73
- targetId
74
- entity {
20
+ title
21
+ status
22
+ promote
23
+ sticky
24
+ revisionTranslationAffected
25
+ body {
26
+ summaryProcessed
27
+ summary
28
+ processed
29
+ format
30
+ value
31
+ }
32
+ fieldText {
33
+ value
34
+ }
35
+ fieldBoolean {
36
+ value
37
+ }
38
+ fieldLink {
75
39
title
76
- fieldReference {
77
- targetId
78
- entity {
79
- title
40
+ uri
41
+ target :attribute (key : " _target" )
42
+ url {
43
+ ... on EntityCanonicalUrl {
44
+ internal :path
45
+ }
46
+ ... on ExternalUrl {
47
+ external :path
80
48
}
81
49
}
50
+
82
51
}
83
- }
84
- fieldFile {
85
- targetId
86
- display
87
- description
88
- entity {
89
- url
90
- uri
52
+ fieldInteger {
53
+ value
91
54
}
92
- }
93
- fieldImage {
94
- targetId
95
- alt
96
- title
97
- width
98
- height
99
- entity {
100
- url
101
- uri
55
+ fieldFloat {
56
+ value
57
+ }
58
+ fieldDecimal {
59
+ value
60
+ }
61
+ fieldDatetime {
62
+ value
63
+ }
64
+ fieldTimestamp {
65
+ value
66
+ }
67
+ fieldEmail {
68
+ value
69
+ }
70
+ fieldString {
71
+ value
72
+ }
73
+ fieldReference {
74
+ targetId
75
+ entity {
76
+ title
77
+ fieldReference {
78
+ targetId
79
+ entity {
80
+ title
81
+ }
82
+ }
83
+ }
84
+ }
85
+ fieldFile {
86
+ targetId
87
+ display
88
+ description
89
+ entity {
90
+ url
91
+ uri
92
+ }
93
+ }
94
+ fieldImage {
95
+ targetId
96
+ alt
97
+ title
98
+ width
99
+ height
100
+ entity {
101
+ url
102
+ uri
103
+ }
102
104
}
103
105
}
104
106
}
You can’t perform that action at this time.
0 commit comments