-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathInformationCollectionMapper.php
More file actions
56 lines (47 loc) · 1.85 KB
/
InformationCollectionMapper.php
File metadata and controls
56 lines (47 loc) · 1.85 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
<?php
declare(strict_types=1);
namespace Netgen\Bundle\InformationCollectionBundle\EzPlatform\RepositoryForms;
use eZ\Publish\API\Repository\Values\Content\Content;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition;
use eZ\Publish\API\Repository\Values\ValueObject;
use Netgen\InformationCollection\API\Value\InformationCollectionStruct;
use Symfony\Component\OptionsResolver\OptionsResolver;
use EzSystems\EzPlatformContentForms\Data\Mapper\FormDataMapperInterface;
use EzSystems\EzPlatformContentForms\Data\Content\FieldData;
final class InformationCollectionMapper
{
/**
* Maps a ValueObject from eZ content repository to a data usable as underlying form data (e.g. create/update struct).
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $contentDraft
* @param array $params
*
* @return InformationCollectionStruct
*/
public function mapToFormData(Content $content, Location $location, ContentType $contentType)
{
$fields = $content->getFieldsByLanguage();
$informationCollectionFields = [];
/** @var FieldDefinition $fieldDef */
foreach ($contentType->fieldDefinitions as $fieldDef) {
if ($fieldDef->isInfoCollector) {
$field = $fields[$fieldDef->identifier];
$fieldData = new FieldData(
[
'fieldDefinition' => $fieldDef,
'field' => $field,
]
);
$informationCollectionFields[] = $fieldData;
}
}
return new InformationCollectionStruct(
$content,
$location,
$contentType,
$informationCollectionFields
);
}
}