-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image asset complex field handler #203
Open
erdnaxelaweb
wants to merge
2
commits into
kaliop-uk:main
Choose a base branch
from
Novactive:fix-ezimageasset-fieldhandler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Kaliop\eZMigrationBundle\Core\FieldHandler; | ||
|
||
use eZ\Publish\Core\FieldType\ImageAsset\Value; | ||
use Kaliop\eZMigrationBundle\API\FieldValueImporterInterface; | ||
use Kaliop\eZMigrationBundle\API\FieldDefinitionConverterInterface; | ||
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 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<section xmlns=\"http://docbook.org/ns/docbook\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:ezxhtml=\"http://ez.no/xmlns/ezpublish/docbook/xhtml\" xmlns:ezcustom=\"http://ez.no/xmlns/ezpublish/docbook/custom\" version=\"5.0-variant ezpublish-1.0\"><para>eZPLatform</para></section>\n" | ||
image: | ||
path: images/blank.jpg | ||
filename: blank.jpg | ||
alternativeText: '' | ||
slide_format: | ||
- 0 |
44 changes: 44 additions & 0 deletions
44
Tests/dsl/UnitTest0192_create_eZImageAsset_content_type.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
- | ||
type: content_type | ||
mode: create | ||
content_type_group: ez | ||
identifier: kaliop_ezimageasset | ||
name: | ||
fre-FR: 'Kaliop' | ||
description: { } | ||
name_pattern: '<title>' | ||
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: { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that the $id is int? I had similar issues when using references https://github.com/ezsystems/ezplatform-ee-demo/blob/v2.5.1/src/AppBundle/Migration/FieldHandler/EzImageAsset.php#L37
is your solution works with content exporter command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @florianalexandre any answer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any plans to merge this?