diff --git a/Core/FieldHandler/EzImageAsset.php b/Core/FieldHandler/EzImageAsset.php new file mode 100644 index 00000000..1c58678d --- /dev/null +++ b/Core/FieldHandler/EzImageAsset.php @@ -0,0 +1,56 @@ +contentMatcher = $contentMatcher; + } + + /** + * Creates a value object to use as the field value when setting an ez image asset 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()) + { + $altText = ''; + + if ($fieldValue === null) { + return new Value(); + } + if (isset($fieldValue['alt_text'])) { + $altText = $fieldValue['alt_text']; + } + + if (is_array($fieldValue) && array_key_exists('destinationContentId', $fieldValue)) { + // fromHash format + $id = $fieldValue['destinationContentId']; + } else { + // simplified format + $id = $fieldValue; + } + + if ($id === null) { + return new Value(); + } + + // 1. resolve relations + $id = $this->referenceResolver->resolveReference($id); + // 2. resolve remote ids + $id = $this->contentMatcher->matchOneByKey($id)->id; + + return new Value($id, $altText); + } +} \ No newline at end of file diff --git a/Resources/config/services.yml b/Resources/config/services.yml index e4dffdc7..c2c0d84e 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -98,6 +98,7 @@ parameters: ez_migration_bundle.complex_field.ezimage.class: Kaliop\eZMigrationBundle\Core\FieldHandler\EzImage ez_migration_bundle.complex_field.ezmedia.class: Kaliop\eZMigrationBundle\Core\FieldHandler\EzMedia ez_migration_bundle.complex_field.ezpage.class: Kaliop\eZMigrationBundle\Core\FieldHandler\EzPage + ez_migration_bundle.complex_field.ezimageasset.class: Kaliop\eZMigrationBundle\Core\FieldHandler\EzImageAsset ez_migration_bundle.complex_field.ezrelation.class: Kaliop\eZMigrationBundle\Core\FieldHandler\EzRelation ez_migration_bundle.complex_field.ezrelationlist.class: Kaliop\eZMigrationBundle\Core\FieldHandler\EzRelationList ez_migration_bundle.complex_field.ezrichtext.class: Kaliop\eZMigrationBundle\Core\FieldHandler\EzRichText @@ -661,6 +662,14 @@ services: tags: - { name: ez_migration_bundle.complex_field, fieldtype: ezobjectrelation, 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 } + ez_migration_bundle.complex_field.ezrelationlist: parent: ez_migration_bundle.complex_field class: '%ez_migration_bundle.complex_field.ezrelationlist.class%' diff --git a/Tests/dsl/UnitTest0190_create_eZImage_content_type.yml b/Tests/dsl/UnitTest0190_create_eZImage_content_type.yml new file mode 100644 index 00000000..ec07f710 --- /dev/null +++ b/Tests/dsl/UnitTest0190_create_eZImage_content_type.yml @@ -0,0 +1,40 @@ +- + type: content_type + mode: update + remove_drafts: true + match: + contenttype_identifier: image + attributes: + - + identifier: slide_format + type: ezselection + name: + fre-FR: Format + description: { } + required: true + searchable: false + info-collector: false + disable-translation: false + category: content + position: 4 + field-settings: + isMultiple: false + options: [Square, Landscape, Portrait] + validator-configuration: { } + +- + type: content + mode: delete + match: + content_type_identifier: gallery_slide +- + type: trash + mode: delete + match: + content_type_identifier: gallery_slide +- + type: content_type + mode: delete + remove_drafts: true + match: + identifier: gallery_slide diff --git a/Tests/dsl/UnitTest0191_create_eZImage_content.yml b/Tests/dsl/UnitTest0191_create_eZImage_content.yml new file mode 100644 index 00000000..a3129a8c --- /dev/null +++ b/Tests/dsl/UnitTest0191_create_eZImage_content.yml @@ -0,0 +1,27 @@ +- + type: content + mode: create + content_type: image + parent_location: 2 + priority: 0 + is_hidden: false + sort_field: path + sort_order: ASC + remote_id: 0c6ca3b36823ab38b9c8a8b79d5b12fd + location_remote_id: f17baf9b7fac9fa91ea2c1f76dcbd39c + lang: fre-FR + section: 1 + owner: 14 + modification_date: 1556889738 + publication_date: 1556889738 + always_available: true + attributes: + name: 'eZPlatform img' + caption: + xml: "\n
eZPLatform
\n" + image: + path: images/blank.jpg + filename: blank.jpg + alternativeText: '' + slide_format: + - 0 diff --git a/Tests/dsl/UnitTest0192_create_eZImageAsset_content_type.yml b/Tests/dsl/UnitTest0192_create_eZImageAsset_content_type.yml new file mode 100644 index 00000000..52486edf --- /dev/null +++ b/Tests/dsl/UnitTest0192_create_eZImageAsset_content_type.yml @@ -0,0 +1,44 @@ +- + type: content_type + mode: create + content_type_group: ez + identifier: kaliop_ezimageasset + name: + fre-FR: 'Kaliop' + description: { } + name_pattern: '' + url_name_pattern: '<title>' + is_container: true + lang: fre-FR + attributes: + - + identifier: title + type: ezstring + name: + fre-FR: Title + description: + fre-FR: 'Title' + required: true + searchable: true + info-collector: false + disable-translation: false + category: content + position: 1 + field-settings: { } + validator-configuration: + StringLengthValidator: { maxStringLength: 250, minStringLength: 1 } + - + identifier: image_vignette + type: ezimageasset + name: + fre-FR: 'Image' + description: + fre-FR: 'Image ezimageasset' + required: false + searchable: true + info-collector: false + disable-translation: false + category: content + position: 4 + field-settings: { } + validator-configuration: { } diff --git a/Tests/dsl/UnitTest0193_create_eZImageAsset_content.yml b/Tests/dsl/UnitTest0193_create_eZImageAsset_content.yml new file mode 100644 index 00000000..c554459e --- /dev/null +++ b/Tests/dsl/UnitTest0193_create_eZImageAsset_content.yml @@ -0,0 +1,22 @@ +- + type: content + mode: create + content_type: kaliop_ezimageasset + parent_location: 2 #HP HDA + priority: 0 + is_hidden: false + sort_field: published + sort_order: DESC + remote_id: a50df951d9eeda40b76ca6a323a958c3 + location_remote_id: b62b6f211fb326f77b9cfea6c6e57944 + lang: fre-FR + section: 1 + owner: 14 + modification_date: 1556869563 + publication_date: 1556813177 + always_available: true + attributes: + title: 'ez platform' + image_vignette: + destinationContentId: 0c6ca3b36823ab38b9c8a8b79d5b12fd + alternativeText: null \ No newline at end of file diff --git a/Tests/dsl/UnitTest0194_delete_all.yml b/Tests/dsl/UnitTest0194_delete_all.yml new file mode 100644 index 00000000..e6df3acc --- /dev/null +++ b/Tests/dsl/UnitTest0194_delete_all.yml @@ -0,0 +1,21 @@ +- + type: content + mode: delete + match: + location_remote_id: f17baf9b7fac9fa91ea2c1f76dcbd39c +- + type: content + mode: delete + match: + location_remote_id: b62b6f211fb326f77b9cfea6c6e57944 +- + type: content_type + mode: delete + match: + identifier: image + +- + type: content_type + mode: delete + match: + identifier: kaliop_ezimageasset diff --git a/Tests/dsl/images/blank.jpg b/Tests/dsl/images/blank.jpg new file mode 100644 index 00000000..1cda9a53 Binary files /dev/null and b/Tests/dsl/images/blank.jpg differ