Completed
Push — master ( 12f48c...b47ac0 )
by Gaetano
06:59
created

EzRelationList::createValue()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 9
c 1
b 0
f 1
nc 6
nop 2
dl 0
loc 18
rs 8.8571
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Core\ComplexField;
4
5
use eZ\Publish\Core\FieldType\RelationList\Value;
6
use Kaliop\eZMigrationBundle\API\ComplexFieldInterface;
7
8
class EzRelationList extends AbstractComplexField implements ComplexFieldInterface
9
{
10
    /**
11
     * @param array $fieldValueArray The definition of the field value, structured in the yml file
12
     * @param array $context The context for execution of the current migrations. Contains f.e. the path to the migration
13
     * @return PageValue
14
     */
15
    public function createValue(array $fieldValueArray, array $context = array())
16
    {
17
        if (count($fieldValueArray) == 1 && isset($fieldValueArray['destinationContentIds'])) {
18
            // fromHash format
19
            $ids = $fieldValueArray['destinationContentIds'];
20
        } else {
21
            // simplified format
22
            $ids = $fieldValueArray;
23
        }
24
25
        foreach ($ids as $key => $id) {
26
            if ($this->referenceResolver->isReference($id)) {
27
                $ids[$key] = $this->referenceResolver->getReferenceValue($id);
28
            }
29
        }
30
31
        return new Value($ids);
32
    }
33
}
34