Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Core/FieldHandler/EzImageAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Kaliop\eZMigrationBundle\Core\FieldHandler;

use Ibexa\Core\FieldType\ImageAsset\Value;
use Kaliop\eZMigrationBundle\API\FieldValueImporterInterface;
use Kaliop\eZMigrationBundle\Core\Matcher\ContentMatcher;

class EzImageAsset extends AbstractFieldHandler implements FieldValueImporterInterface
{
protected $contentMatcher;

public function __construct(ContentMatcher $contentMatcher)
{
$this->contentMatcher = $contentMatcher;
}

/**
* Creates a value object to use as the field value when setting an ez relation field type.
*
* @param array|string|int $fieldValue The definition of the field value, structured in the yml file
* @param array $context The context for execution of the current migrations. Contains f.e. the path to the migration
* @return Value
*/
public function hashToFieldValue($fieldValue, array $context = array())
{
$id = null;
$alternativeText = null;
if (is_array($fieldValue)) {
if (array_key_exists('destinationContentId', $fieldValue)) {
$id = $fieldValue['destinationContentId'];
}
if (array_key_exists('alternativeText', $fieldValue)) {
$alternativeText = $fieldValue['alternativeText'];
}
} elseif (!empty($fieldValue)) {
// simplified format
$id = $fieldValue;
}

if ($id === null) {
return new Value();
}

// 1. resolve relations
// NB: this might result in double reference-resolving when the original value is a string, given preResolveReferences...
$id = $this->referenceResolver->resolveReference($id);
// 2. resolve remote ids
$id = $this->contentMatcher->matchOneByKey($id)->id;

return new Value($id, $alternativeText);
}
}
9 changes: 9 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ parameters:
ez_migration_bundle.complex_field.ezselection.class: Kaliop\eZMigrationBundle\Core\FieldHandler\EzSelection
ez_migration_bundle.complex_field.ezxmltext.class: Kaliop\eZMigrationBundle\Core\FieldHandler\EzXmlText
ez_migration_bundle.complex_field.eztags.class: Kaliop\eZMigrationBundle\Core\FieldHandler\EzTags
ez_migration_bundle.complex_field.ezimageasset.class: Kaliop\eZMigrationBundle\Core\FieldHandler\EzImageAsset

ez_migration_bundle.reference_resolver.chain.class: Kaliop\eZMigrationBundle\Core\ReferenceResolver\ChainResolver
ez_migration_bundle.reference_resolver.chain_prefix.class: Kaliop\eZMigrationBundle\Core\ReferenceResolver\ChainPrefixResolver
Expand Down Expand Up @@ -800,6 +801,14 @@ services:
tags:
- { name: ez_migration_bundle.complex_field, fieldtype: eztags, priority: 0 }

ez_migration_bundle.complex_field.ezimageasset:
parent: ez_migration_bundle.complex_field
class: '%ez_migration_bundle.complex_field.ezimageasset.class%'
arguments:
- '@ez_migration_bundle.content_matcher'
tags:
- { name: ez_migration_bundle.complex_field, fieldtype: ezimageasset, priority: 0 }

### reference resolvers

# A service that will resolve *any* possible reference. To be used with care
Expand Down
5 changes: 5 additions & 0 deletions WHATSNEW.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version: 1.0.5
==============

* Added: support to import `ezimageasset` field type

Version: 1.0.4
==============

Expand Down
Loading