-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathRelationListFieldValueBuilder.php
More file actions
69 lines (57 loc) · 2.08 KB
/
RelationListFieldValueBuilder.php
File metadata and controls
69 lines (57 loc) · 2.08 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace BD\EzPlatformGraphQLBundle\DomainContent\FieldValueBuilder;
use BD\EzPlatformGraphQLBundle\DomainContent\NameHelper;
use eZ\Publish\API\Repository\ContentTypeService;
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition;
class RelationListFieldValueBuilder implements FieldValueBuilder
{
/**
* @var NameHelper
*/
private $nameHelper;
/**
* @var ContentTypeService
*/
private $contentTypeService;
public function __construct(NameHelper $nameHelper, ContentTypeService $contentTypeService)
{
$this->nameHelper = $nameHelper;
$this->contentTypeService = $contentTypeService;
}
public function buildDefinition(FieldDefinition $fieldDefinition)
{
$settings = $fieldDefinition->getFieldSettings();
$constraints = $fieldDefinition->getValidatorConfiguration();
if (count($settings['selectionContentTypes']) === 1) {
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($settings['selectionContentTypes'][0]);
$type = $this->nameHelper->domainContentName($contentType);
} else {
$type = 'DomainContent';
}
$isMultiple = 'false';
if ($constraints['RelationListValueValidator']['selectionLimit'] !== 1) {
$isMultiple = 'true';
$type = "[$type]";
}
$resolver = sprintf(
'@=resolver("DomainRelationFieldValue", [value, "%s", %s])',
$fieldDefinition->identifier,
$isMultiple
);
$field = [
'type' => $type,
'resolve' => $resolver
];
if (isset($contentType)) {
$field['public'] = sprintf(
'@=service("ezplatform_graphql.can_user").viewContentOfType("%s")',
$contentType->identifier
);
}
return $field;
}
private function mapFieldTypeIdentifierToGraphQLType($fieldTypeIdentifier)
{
return isset($this->typesMap[$fieldTypeIdentifier]) ? $this->typesMap[$fieldTypeIdentifier] : 'GenericFieldValue';
}
}