diff --git a/Core/FieldHandler/EzImageAsset.php b/Core/FieldHandler/EzImageAsset.php new file mode 100644 index 0000000..405b2bb --- /dev/null +++ b/Core/FieldHandler/EzImageAsset.php @@ -0,0 +1,53 @@ +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); + } +} diff --git a/Resources/config/services.yml b/Resources/config/services.yml index f9d8215..d99eade 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -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 @@ -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 diff --git a/WHATSNEW.md b/WHATSNEW.md index 3a8fb14..0a774fd 100644 --- a/WHATSNEW.md +++ b/WHATSNEW.md @@ -1,3 +1,8 @@ +Version: 1.0.5 +============== + +* Added: support to import `ezimageasset` field type + Version: 1.0.4 ==============