-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathAdapterResolver.php
More file actions
154 lines (134 loc) · 5.64 KB
/
AdapterResolver.php
File metadata and controls
154 lines (134 loc) · 5.64 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
declare(strict_types=1);
/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/
namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver\DataObject;
use Exception;
use Pimcore\Bundle\StaticResolverBundle\Lib\ToolResolverInterface;
use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\LocalizedFieldResolverInterface;
use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\DataObjectServiceResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\FieldContextData;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\Model\InheritanceData;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\InheritanceServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\CoreElementColumnResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ExportResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData;
use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Trait\ColumnDataTrait;
use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Trait\FieldDefinitionTrait;
use Pimcore\Bundle\StudioBackendBundle\Grid\Util\Trait\LocalizedValueTrait;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementTypes;
use Pimcore\Model\DataObject\ClassDefinition\Data;
use Pimcore\Model\DataObject\Concrete;
use Pimcore\Model\Element\ElementInterface;
use Pimcore\Model\UserInterface;
/**
* @internal
*/
final class AdapterResolver implements
ColumnResolverInterface,
CoreElementColumnResolverInterface,
ExportResolverInterface
{
use ColumnDataTrait;
use LocalizedValueTrait;
use FieldDefinitionTrait;
public function __construct(
private readonly DataServiceInterface $dataService,
private readonly InheritanceServiceInterface $inheritanceService,
private readonly DataObjectServiceResolverInterface $dataObjectServiceResolver,
private readonly ToolResolverInterface $toolResolver,
private readonly LocalizedFieldResolverInterface $localizedFieldResolver,
) {
}
/** @see LocalizedValueTrait::doGetFallbackValues() */
protected function doGetFallbackValues(): bool
{
return $this->localizedFieldResolver->doGetFallbackValues();
}
/** @see LocalizedValueTrait::getDefaultLanguage() */
protected function getDefaultLanguage(): ?string
{
return $this->toolResolver->getDefaultLanguage();
}
/**
* @throws Exception
* @throws InvalidArgumentException
* @throws NotFoundException
*/
public function resolveForExport(Column $column, ElementInterface $element, UserInterface $user): ColumnData
{
if (!$element instanceof Concrete) {
throw new InvalidArgumentException('Element must be a concrete object');
}
$classDefinition = $element->getClass();
$fieldDefinition = $this->getFieldDefinition($column->getKey(), $classDefinition);
$context = new FieldContextData(
legacyParameters: ['language' => $column->getLocale()]
);
$value = $this->dataService->getExportFieldValue($element, $fieldDefinition, $column->getKey(), $context);
return $this->getColumnData($column, $value, $fieldDefinition->getFieldType());
}
/**
* @throws Exception
* @throws InvalidArgumentException
* @throws NotFoundException
*/
public function resolveForCoreElement(Column $column, ElementInterface $element): ColumnData
{
if (!$element instanceof Concrete) {
throw new InvalidArgumentException('Element must be a concrete object');
}
$classDefinition = $element->getClass();
$fieldDefinition = $this->getFieldDefinition($column->getKey(), $classDefinition);
$value = $this->dataService->getNormalizedValue(
$this->getLocalizedValue($column, $element),
$fieldDefinition
);
$inheritanceData = null;
if ($classDefinition->getAllowInherit() && $fieldDefinition->supportsInheritance()) {
$inheritanceData = $this->getInheritanceData($element, $fieldDefinition, $column);
}
return $this->getColumnData(
$column,
$value,
$fieldDefinition->getFieldType(),
$inheritanceData
);
}
public function getType(): string
{
return 'dataobject.adapter';
}
public function supportedElementTypes(): array
{
return [
ElementTypes::TYPE_OBJECT,
];
}
private function getInheritanceData(Concrete $element, Data $fieldDefinition, Column $column): array|InheritanceData
{
return $this->dataObjectServiceResolver->useInheritedValues(
false,
function () use ($element, $fieldDefinition, $column) {
return $this->inheritanceService->processFieldDefinition(
$element,
$fieldDefinition,
$column->getKey(),
new FieldContextData(contextObject: null, language: $column->getLocale())
);
}
);
}
}