-
Notifications
You must be signed in to change notification settings - Fork 611
/
Mutation.php
52 lines (44 loc) · 1.46 KB
/
Mutation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\gql\base;
use craft\base\FieldInterface;
/**
* Class Mutation
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 3.5.0
*/
abstract class Mutation
{
use GqlTypeTrait;
/**
* Returns the mutations defined by the class as an array.
*
* @return array
*/
abstract public static function getMutations(): array;
/**
* Load content fields and value normalizers on the resolver, based on content fields.
*
* @param MutationResolver $resolver
* @param FieldInterface[] $contentFields
*/
protected static function prepareResolver(MutationResolver $resolver, array $contentFields): void
{
$fieldList = [];
foreach ($contentFields as $contentField) {
$contentFieldType = $contentField->getContentGqlMutationArgumentType();
$handle = $contentField->handle;
$fieldList[$handle] = $contentFieldType;
$configArray = is_array($contentFieldType) ? $contentFieldType : $contentFieldType->config;
if (is_array($configArray) && !empty($configArray['normalizeValue'])) {
$resolver->setValueNormalizer($handle, $configArray['normalizeValue']);
}
}
$resolver->setResolutionData(ElementMutationResolver::CONTENT_FIELD_KEY, $fieldList);
}
}