|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SEOmatic plugin for Craft CMS 3.x |
|
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 nystudio107\seomatic\gql\types\generators\SeomaticGenerator; |
|
15
|
|
|
|
|
16
|
|
|
use craft\gql\base\InterfaceType as BaseInterfaceType; |
|
17
|
|
|
use craft\gql\TypeLoader; |
|
18
|
|
|
use craft\gql\GqlEntityRegistry; |
|
19
|
|
|
|
|
20
|
|
|
use GraphQL\Type\Definition\InterfaceType; |
|
21
|
|
|
use GraphQL\Type\Definition\Type; |
|
22
|
|
|
use nystudio107\seomatic\models\MetaJsonLdContainer; |
|
23
|
|
|
use nystudio107\seomatic\models\MetaLinkContainer; |
|
24
|
|
|
use nystudio107\seomatic\models\MetaScriptContainer; |
|
25
|
|
|
use nystudio107\seomatic\models\MetaTagContainer; |
|
26
|
|
|
use nystudio107\seomatic\models\MetaTitleContainer; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Class SeomaticInterface |
|
30
|
|
|
* |
|
31
|
|
|
* @author nystudio107 |
|
|
|
|
|
|
32
|
|
|
* @package Seomatic |
|
33
|
|
|
* @since 3.2.8 |
|
|
|
|
|
|
34
|
|
|
*/ |
|
35
|
|
|
class SeomaticInterface extends BaseInterfaceType |
|
36
|
|
|
{ |
|
37
|
|
|
// Constants |
|
38
|
|
|
// ========================================================================= |
|
39
|
|
|
|
|
40
|
|
|
const GRAPH_QL_FIELDS = [ |
|
41
|
|
|
'metaTitleContainer' => MetaTitleContainer::CONTAINER_TYPE, |
|
42
|
|
|
'metaTagContainer' => MetaTagContainer::CONTAINER_TYPE, |
|
43
|
|
|
'metaLinkContainer' => MetaLinkContainer::CONTAINER_TYPE, |
|
44
|
|
|
'metaScriptContainer' => MetaScriptContainer::CONTAINER_TYPE, |
|
45
|
|
|
'metaJsonLdContainer' => MetaJsonLdContainer::CONTAINER_TYPE, |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @inheritdoc |
|
50
|
|
|
*/ |
|
51
|
|
|
public static function getTypeGenerator(): string |
|
52
|
|
|
{ |
|
53
|
|
|
return SeomaticGenerator::class; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
|
|
|
|
|
57
|
|
|
* @inheritdoc |
|
58
|
|
|
*/ |
|
59
|
|
|
public static function getType($fields = null): Type |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
if ($type = GqlEntityRegistry::getEntity(self::class)) { |
|
62
|
|
|
return $type; |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$type = GqlEntityRegistry::createEntity(self::class, new InterfaceType([ |
|
66
|
|
|
'name' => static::getName(), |
|
67
|
|
|
'fields' => self::class.'::getFieldDefinitions', |
|
68
|
|
|
'description' => 'This is the interface implemented by SEOmatic.', |
|
69
|
|
|
'resolveType' => function (array $value) { |
|
|
|
|
|
|
70
|
|
|
return GqlEntityRegistry::getEntity(SeomaticGenerator::getName()); |
|
71
|
|
|
}, |
|
72
|
|
|
])); |
|
73
|
|
|
|
|
74
|
|
|
foreach (SeomaticGenerator::generateTypes() as $typeName => $generatedType) { |
|
75
|
|
|
TypeLoader::registerType($typeName, function () use ($generatedType) { |
|
76
|
|
|
return $generatedType; |
|
77
|
|
|
}); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $type; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @inheritdoc |
|
85
|
|
|
*/ |
|
86
|
|
|
public static function getName(): string |
|
87
|
|
|
{ |
|
88
|
|
|
return 'SeomaticInterface'; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @inheritdoc |
|
93
|
|
|
*/ |
|
94
|
|
|
public static function getFieldDefinitions(): array |
|
95
|
|
|
{ |
|
96
|
|
|
$fields = []; |
|
97
|
|
|
foreach (self::GRAPH_QL_FIELDS as $key => $value) { |
|
98
|
|
|
$fields[$key] = [ |
|
99
|
|
|
'name' => $key, |
|
100
|
|
|
'type' => Type::string(), |
|
101
|
|
|
'description' => 'The '.$value.' SEOmatic container.', |
|
102
|
|
|
]; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return $fields; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|