|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SEOmatic plugin for Craft CMS |
|
4
|
|
|
* |
|
5
|
|
|
* A turnkey SEO implementation for Craft CMS that is comprehensive, powerful, |
|
6
|
|
|
* and flexible |
|
7
|
|
|
* |
|
8
|
|
|
* @link https://nystudio107.com |
|
9
|
|
|
* @copyright Copyright (c) 2019 nystudio107 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace nystudio107\seomatic\gql\interfaces; |
|
13
|
|
|
|
|
14
|
|
|
use craft\gql\base\InterfaceType as BaseInterfaceType; |
|
15
|
|
|
use craft\gql\GqlEntityRegistry; |
|
16
|
|
|
use GraphQL\Type\Definition\InterfaceType; |
|
17
|
|
|
use GraphQL\Type\Definition\Type; |
|
18
|
|
|
use nystudio107\seomatic\gql\arguments\FrontendContainerArguments; |
|
19
|
|
|
use nystudio107\seomatic\gql\arguments\SitemapArguments; |
|
20
|
|
|
|
|
21
|
|
|
use nystudio107\seomatic\gql\arguments\SitemapIndexArguments; |
|
22
|
|
|
use nystudio107\seomatic\gql\resolvers\FrontendContainerResolver; |
|
23
|
|
|
use nystudio107\seomatic\gql\resolvers\SitemapResolver; |
|
24
|
|
|
use nystudio107\seomatic\gql\types\FileContentsType; |
|
25
|
|
|
use nystudio107\seomatic\gql\types\generators\SeomaticGenerator; |
|
26
|
|
|
use nystudio107\seomatic\models\FrontendTemplateContainer; |
|
27
|
|
|
use nystudio107\seomatic\models\MetaJsonLdContainer; |
|
28
|
|
|
use nystudio107\seomatic\models\MetaLinkContainer; |
|
29
|
|
|
|
|
30
|
|
|
use nystudio107\seomatic\models\MetaScriptContainer; |
|
31
|
|
|
use nystudio107\seomatic\models\MetaSiteVars; |
|
32
|
|
|
|
|
33
|
|
|
use nystudio107\seomatic\models\MetaTagContainer; |
|
34
|
|
|
use nystudio107\seomatic\models\MetaTitleContainer; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Class SeomaticInterface |
|
38
|
|
|
* |
|
39
|
|
|
* @author nystudio107 |
|
40
|
|
|
* @package Seomatic |
|
41
|
|
|
* @since 3.2.8 |
|
42
|
|
|
*/ |
|
43
|
|
|
class SeomaticInterface extends BaseInterfaceType |
|
44
|
|
|
{ |
|
45
|
|
|
// Constants |
|
46
|
|
|
// ========================================================================= |
|
47
|
|
|
|
|
48
|
|
|
public const GRAPH_QL_FIELDS = [ |
|
49
|
|
|
'metaTitleContainer' => MetaTitleContainer::CONTAINER_TYPE, |
|
50
|
|
|
'metaTagContainer' => MetaTagContainer::CONTAINER_TYPE, |
|
51
|
|
|
'metaLinkContainer' => MetaLinkContainer::CONTAINER_TYPE, |
|
52
|
|
|
'metaScriptContainer' => MetaScriptContainer::CONTAINER_TYPE, |
|
53
|
|
|
'metaJsonLdContainer' => MetaJsonLdContainer::CONTAINER_TYPE, |
|
54
|
|
|
'metaSiteVarsContainer' => MetaSiteVars::CONTAINER_TYPE, |
|
55
|
|
|
'frontendTemplateContainer' => FrontendTemplateContainer::CONTAINER_TYPE, |
|
56
|
|
|
]; |
|
57
|
|
|
|
|
58
|
|
|
public const DEPRECATED_GRAPH_QL_FIELDS = [ |
|
59
|
|
|
'frontendTemplateContainer' => 'This query is deprecated and will be removed in the future. You should use `frontendTemplates` instead.', |
|
60
|
|
|
]; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @inheritdoc |
|
64
|
|
|
*/ |
|
65
|
|
|
public static function getTypeGenerator(): string |
|
66
|
|
|
{ |
|
67
|
|
|
return SeomaticGenerator::class; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @inheritdoc |
|
72
|
|
|
*/ |
|
73
|
|
|
public static function getType($fields = null): Type |
|
|
|
|
|
|
74
|
|
|
{ |
|
75
|
|
|
if ($type = GqlEntityRegistry::getEntity(self::class)) { |
|
76
|
|
|
return $type; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$type = GqlEntityRegistry::createEntity(self::class, new InterfaceType([ |
|
80
|
|
|
'name' => static::getName(), |
|
81
|
|
|
'fields' => self::class . '::getFieldDefinitions', |
|
82
|
|
|
'description' => 'This is the interface implemented by SEOmatic.', |
|
83
|
|
|
'resolveType' => function(array $value) { |
|
|
|
|
|
|
84
|
|
|
return GqlEntityRegistry::getEntity(SeomaticGenerator::getName()); |
|
85
|
|
|
}, |
|
86
|
|
|
])); |
|
87
|
|
|
SeomaticGenerator::generateTypes(); |
|
88
|
|
|
|
|
89
|
|
|
return $type; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @inheritdoc |
|
94
|
|
|
*/ |
|
95
|
|
|
public static function getName(): string |
|
96
|
|
|
{ |
|
97
|
|
|
return 'SeomaticInterface'; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @inheritdoc |
|
102
|
|
|
*/ |
|
103
|
|
|
public static function getFieldDefinitions(): array |
|
104
|
|
|
{ |
|
105
|
|
|
$fields = []; |
|
106
|
|
|
foreach (self::GRAPH_QL_FIELDS as $key => $value) { |
|
107
|
|
|
$fields[$key] = [ |
|
108
|
|
|
'name' => $key, |
|
109
|
|
|
'type' => Type::string(), |
|
110
|
|
|
'description' => 'The ' . $value . ' SEOmatic container.', |
|
111
|
|
|
]; |
|
112
|
|
|
if (isset(self::DEPRECATED_GRAPH_QL_FIELDS[$key])) { |
|
113
|
|
|
$fields[$key]['deprecationReason'] = self::DEPRECATED_GRAPH_QL_FIELDS[$key]; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$fields['sitemaps'] = [ |
|
118
|
|
|
'name' => 'sitemaps', |
|
119
|
|
|
'args' => SitemapArguments::getArguments(), |
|
120
|
|
|
'type' => Type::listOf(FileContentsType::getType()), |
|
121
|
|
|
'resolve' => SitemapResolver::class . '::getSitemaps', |
|
122
|
|
|
]; |
|
123
|
|
|
|
|
124
|
|
|
$fields['sitemapIndexes'] = [ |
|
125
|
|
|
'name' => 'sitemapIndexes', |
|
126
|
|
|
'args' => SitemapIndexArguments::getArguments(), |
|
127
|
|
|
'type' => Type::listOf(FileContentsType::getType()), |
|
128
|
|
|
'resolve' => SitemapResolver::class . '::getSitemapIndexes', |
|
129
|
|
|
]; |
|
130
|
|
|
|
|
131
|
|
|
$fields['sitemapStyles'] = [ |
|
132
|
|
|
'name' => 'sitemapStyles', |
|
133
|
|
|
'type' => FileContentsType::getType(), |
|
134
|
|
|
'resolve' => SitemapResolver::class . '::getSitemapStyles', |
|
135
|
|
|
]; |
|
136
|
|
|
|
|
137
|
|
|
$fields['frontendTemplates'] = [ |
|
138
|
|
|
'name' => 'frontendTemplates', |
|
139
|
|
|
'args' => FrontendContainerArguments::getArguments(), |
|
140
|
|
|
'type' => Type::listOf(FileContentsType::getType()), |
|
141
|
|
|
'resolve' => FrontendContainerResolver::class . '::getContainerFiles', |
|
142
|
|
|
]; |
|
143
|
|
|
|
|
144
|
|
|
return $fields; |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.