diff --git a/Resources/public/js/views/fields/ez-relation-editview.js b/Resources/public/js/views/fields/ez-relation-editview.js index e1a60f19..a21eb2f4 100644 --- a/Resources/public/js/views/fields/ez-relation-editview.js +++ b/Resources/public/js/views/fields/ez-relation-editview.js @@ -67,8 +67,7 @@ YUI.add('ez-relation-editview', function (Y) { _fireLoadFieldRelatedContent: function () { if ( !this._isFieldEmpty() ) { this.fire('loadFieldRelatedContent', { - fieldDefinitionIdentifier: this.get('fieldDefinition').identifier, - content: this.get('content'), + destinationContentId: this.get('field').fieldValue.destinationContentHref }); } }, diff --git a/Resources/public/js/views/fields/ez-relationlist-editview.js b/Resources/public/js/views/fields/ez-relationlist-editview.js index 00da8be0..14506391 100644 --- a/Resources/public/js/views/fields/ez-relationlist-editview.js +++ b/Resources/public/js/views/fields/ez-relationlist-editview.js @@ -101,9 +101,7 @@ YUI.add('ez-relationlist-editview', function (Y) { _fireLoadObjectRelations: function () { if ( !this._isFieldEmpty() ) { this.fire('loadObjectRelations', { - relationType: 'ATTRIBUTE', - fieldDefinitionIdentifier: this.get('fieldDefinition').identifier, - content: this.get('content'), + destinationContentIds: this.get('field').fieldValue.destinationContentHrefs }); } }, diff --git a/Resources/public/js/views/services/plugins/ez-objectrelationloadplugin.js b/Resources/public/js/views/services/plugins/ez-objectrelationloadplugin.js index e7dfd4dc..0249d580 100644 --- a/Resources/public/js/views/services/plugins/ez-objectrelationloadplugin.js +++ b/Resources/public/js/views/services/plugins/ez-objectrelationloadplugin.js @@ -36,20 +36,25 @@ YUI.add('ez-objectrelationloadplugin', function (Y) { _loadFieldRelatedContent: function (e) { var loadOptions = {api: this.get('host').get('capi')}, relatedContent = this.get('relatedContent'), + destinationContentId = e.destinationContentId, sourceContent = e.content, contentDestination; - if ( !sourceContent ) { - console.log('[DEPRECATED] loadFieldRelatedContent event without a source content is deprecated'); - console.log('[DEPRECATED] Please provide a source Content item in the event facade under the `content` identifier'); - console.log('[DEPRECATED] This feature will be removed from PlatformUI 2.0'); - sourceContent = this.get('host').get('content'); + if ( !destinationContentId ) { + if ( !sourceContent ) { + console.log('[DEPRECATED] loadFieldRelatedContent event without a source content is deprecated'); + console.log('[DEPRECATED] Please provide a source Content item in the event facade under the `content` identifier'); + console.log('[DEPRECATED] This feature will be removed from PlatformUI 2.0'); + sourceContent = this.get('host').get('content'); + } + contentDestination = sourceContent.relations( + 'ATTRIBUTE', e.fieldDefinitionIdentifier + ).shift(); + + destinationContentId = contentDestination.destination; } - contentDestination = sourceContent.relations( - 'ATTRIBUTE', e.fieldDefinitionIdentifier - ).shift(); - relatedContent.set('id', contentDestination.destination); + relatedContent.set('id', destinationContentId); relatedContent.load(loadOptions, function (error) { if (error) { e.target.set("loadingError", true); diff --git a/Resources/public/js/views/services/plugins/ez-objectrelationsloadplugin.js b/Resources/public/js/views/services/plugins/ez-objectrelationsloadplugin.js index 0141ddf1..8c1d5f9b 100644 --- a/Resources/public/js/views/services/plugins/ez-objectrelationsloadplugin.js +++ b/Resources/public/js/views/services/plugins/ez-objectrelationsloadplugin.js @@ -47,6 +47,7 @@ YUI.add('ez-objectrelationsloadplugin', function (Y) { loadedRelation = {}, loadingError = false, sourceContent = e.content, + destinationContentIds = e.destinationContentIds, contentDestinations, end = stack.add(function (error, struct) { if (error) { @@ -57,24 +58,29 @@ YUI.add('ez-objectrelationsloadplugin', function (Y) { } }); - if ( !sourceContent ) { - console.log('[DEPRECATED] loadObjectRelations event without a source content is deprecated'); - console.log('[DEPRECATED] Please provide a source Content item in the event facade under the `content` identifier'); - console.log('[DEPRECATED] This feature will be removed from PlatformUI 2.0'); - sourceContent = this.get('host').get('content'); + if ( !destinationContentIds ) { + if ( !sourceContent ) { + console.log('[DEPRECATED] loadObjectRelations event without a source content is deprecated'); + console.log('[DEPRECATED] Please provide a source Content item in the event facade under the `content` identifier'); + console.log('[DEPRECATED] This feature will be removed from PlatformUI 2.0'); + sourceContent = this.get('host').get('content'); + } + contentDestinations = sourceContent.relations( + e.relationType, e.fieldDefinitionIdentifier + ); + destinationContentIds = Y.Array.map(contentDestinations, function (value) { + return value.destination; + }); } - contentDestinations = sourceContent.relations( - e.relationType, e.fieldDefinitionIdentifier - ); - Y.Array.each(contentDestinations, function (value) { - if (!loadedRelation[value.destination]) { - loadedRelation[value.destination] = true; + Y.Array.each(destinationContentIds, function (value) { + if (!loadedRelation[value]) { + loadedRelation[value] = true; if (e.loadLocation || e.loadLocationPath) { - this._loadContentStruct(value.destination, e.loadLocation, e.loadLocationPath, end); + this._loadContentStruct(value, e.loadLocation, e.loadLocationPath, end); } else { - this._loadContent(value.destination, end); + this._loadContent(value, end); } } }, this); diff --git a/Tests/js/views/fields/assets/ez-relation-editview-tests.js b/Tests/js/views/fields/assets/ez-relation-editview-tests.js index c6fd2fa5..a49b2650 100644 --- a/Tests/js/views/fields/assets/ez-relation-editview-tests.js +++ b/Tests/js/views/fields/assets/ez-relation-editview-tests.js @@ -35,7 +35,12 @@ YUI.add('ez-relation-editview-tests', function (Y) { isRequired: false, fieldSettings: {}, }; - this.field = {fieldValue: {destinationContentId: 45}}; + this.field = { + fieldValue: { + destinationContentId: 45, + destinationContentHref: '/api/ezp/v2/content/objects/45', + } + }; this.jsonContent = {}; this.jsonContentType = {}; @@ -173,14 +178,9 @@ YUI.add('ez-relation-editview-tests', function (Y) { this.view.on('loadFieldRelatedContent', Y.bind(function (e) { Y.Assert.areSame( - this.fieldDefinitionIdentifier, - e.fieldDefinitionIdentifier, - "fieldDefinitionIdentifier is the same than the one in the field" - ); - Y.Assert.areSame( - this.content, - e.content, - "The content should be provided in the event facade" + this.field.fieldValue.destinationContentHref, + e.destinationContentId, + "destinationContentId is the same than the one in the field" ); loadContentEvent = true; diff --git a/Tests/js/views/fields/assets/ez-relationlist-editview-tests.js b/Tests/js/views/fields/assets/ez-relationlist-editview-tests.js index ade99008..b0cd41fd 100644 --- a/Tests/js/views/fields/assets/ez-relationlist-editview-tests.js +++ b/Tests/js/views/fields/assets/ez-relationlist-editview-tests.js @@ -30,7 +30,15 @@ YUI.add('ez-relationlist-editview-tests', function (Y) { identifier: this.fieldDefinitionIdentifier, isRequired: false }; - this.field = {fieldValue: {destinationContentIds: [45, 42]}}; + this.field = { + fieldValue: { + destinationContentIds: [45, 42], + destinationContentHrefs: [ + '/api/ezp/v2/content/objects/45', + '/api/ezp/v2/content/objects/42', + ] + } + }; this.jsonContent = {}; this.jsonContentType = {}; @@ -646,14 +654,9 @@ YUI.add('ez-relationlist-editview-tests', function (Y) { this.view.on('loadObjectRelations', Y.bind(function (e) { Y.Assert.areSame( - this.fieldDefinitionIdentifier, - e.fieldDefinitionIdentifier, - "fieldDefinitionIdentifier is the same than the one in the field" - ); - Y.Assert.areSame( - this.content, - e.content, - "The content should be provided in the event facade" + this.field.fieldValue.destinationContentHrefs, + e.destinationContentIds, + "destinationContentIds is the same than the one in the field" ); loadContentEvent = true;