From 1d9dc775dbb4aaf4b3a8280328865c7131f178a8 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Mon, 8 Jul 2024 14:45:36 -0300 Subject: [PATCH] Changes condition for sending actions in item edition form. --- .../components/edition/item-edition-form.vue | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/views/admin/components/edition/item-edition-form.vue b/src/views/admin/components/edition/item-edition-form.vue index 74e62cc9e..bd4899dd0 100644 --- a/src/views/admin/components/edition/item-edition-form.vue +++ b/src/views/admin/components/edition/item-edition-form.vue @@ -1326,9 +1326,16 @@ export default { parentMetaId: 0 }); } - - if ( this.collection && this.item ) - wp.hooks.doAction('tainacan_item_edition_item_loaded', JSON.parse(JSON.stringify(this.collection)), JSON.parse(JSON.stringify(this.item))); + /** + * Fires action tainacan_item_edition_item_loaded + * once the existing item is loaded. We cannot reliabilily send collection here since + * it is loaded async outside of the component. + */ + wp.hooks.doAction( + 'tainacan_item_edition_item_loaded', + this.collection ? JSON.parse(JSON.stringify(this.collection)) : false, + this.item ? JSON.parse(JSON.stringify(this.item)) : false + ); // Loads metadata and attachments this.loadMetadata(); @@ -1371,8 +1378,17 @@ export default { } } - if ( this.collection && this.item && metadata) - wp.hooks.doAction('tainacan_item_edition_metadata_loaded', JSON.parse(JSON.stringify(this.collection)), JSON.parse(JSON.stringify(this.item)), metadata); + /** + * Fires action tainacan_item_edition_metadata_loaded + * once the metadata is loaded. We cannot reliabilily send collection here since + * it is loaded async outside of the component. + */ + wp.hooks.doAction( + 'tainacan_item_edition_metadata_loaded', + this.colection ? JSON.parse(JSON.stringify(this.collection)) : false, + this.item ? JSON.parse(JSON.stringify(this.item)) : false, + metadata ? metadata : [] + ); this.isLoading = false; }); @@ -1770,9 +1786,17 @@ export default { this.urlIframeWidth = this.form.document_options['forced_iframe_width']; if (this.form.document_options !== undefined && this.form.document_options['forced_iframe_height'] !== undefined) this.urlIframeHeight = this.form.document_options['forced_iframe_height']; - - if ( this.collection && this.item ) - wp.hooks.doAction('tainacan_item_edition_item_loaded', JSON.parse(JSON.stringify(this.collection)), JSON.parse(JSON.stringify(this.item))); + + /** + * Fires action tainacan_item_edition_item_loaded + * once the existing item is loaded. We cannot reliabilily send collection here since + * it is loaded async outside of the component. + */ + wp.hooks.doAction( + 'tainacan_item_edition_item_loaded', + this.collection ? JSON.parse(JSON.stringify(this.collection)) : false, + this.item ? JSON.parse(JSON.stringify(this.item)) : false + ); this.loadMetadata(); this.setLastUpdated(this.item.modification_date);