|
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\resolvers; |
|
13
|
|
|
|
|
14
|
|
|
use craft\base\Element; |
|
15
|
|
|
use craft\gql\base\Resolver; |
|
16
|
|
|
|
|
17
|
|
|
use craft\helpers\Json; |
|
18
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
|
19
|
|
|
use nystudio107\seomatic\gql\interfaces\SeomaticInterface; |
|
20
|
|
|
use nystudio107\seomatic\helpers\Container as ContainerHelper; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class SeomaticResolver |
|
24
|
|
|
* |
|
25
|
|
|
* @author nystudio107 |
|
|
|
|
|
|
26
|
|
|
* @package Seomatic |
|
27
|
|
|
* @since 3.2.8 |
|
|
|
|
|
|
28
|
|
|
*/ |
|
29
|
|
|
class SeomaticResolver extends Resolver |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
|
|
|
|
|
32
|
|
|
* @inheritDoc |
|
33
|
|
|
*/ |
|
34
|
|
|
public static function resolve($source, array $arguments, $context, ResolveInfo $resolveInfo) |
|
35
|
|
|
{ |
|
36
|
|
|
// If our source is an Element, extract the URI and siteId from it |
|
37
|
|
|
if ($source instanceof Element) { |
|
38
|
|
|
/** Element $source */ |
|
|
|
|
|
|
39
|
|
|
$uri = $source->uri; |
|
40
|
|
|
$siteId = $source->siteId; |
|
41
|
|
|
} else { |
|
42
|
|
|
// Otherwise use the passed in arguments, or defaults |
|
43
|
|
|
$uri = $arguments['uri'] ?? '/'; |
|
44
|
|
|
$siteId = $arguments['siteId'] ?? null; |
|
45
|
|
|
} |
|
46
|
|
|
$asArray = $arguments['asArray'] ?? false; |
|
47
|
|
|
$uri = trim($uri === '/' ? '__home__' : $uri, '/'); |
|
48
|
|
|
|
|
49
|
|
|
$result = ContainerHelper::getContainerArrays( |
|
50
|
|
|
array_values(SeomaticInterface::GRAPH_QL_FIELDS), |
|
51
|
|
|
$uri, |
|
52
|
|
|
$siteId, |
|
53
|
|
|
$asArray |
|
54
|
|
|
); |
|
55
|
|
|
foreach ($result as $key => $value) { |
|
56
|
|
|
if (isset($value) && is_array($value)) { |
|
57
|
|
|
$result[$key] = Json::encode($value); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $result; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|