Fixes missing button in the attachments media modal.

This commit is contained in:
mateuswetah 2024-07-29 12:12:06 -03:00
parent 5b92e61f81
commit 2e75e4e264
2 changed files with 5 additions and 43 deletions

View File

@ -1661,7 +1661,7 @@ export default {
'my-attachment-media-frame', { 'my-attachment-media-frame', {
button_labels: { button_labels: {
frame_title: this.$i18n.get('instruction_select_files_to_attach_to_item'), frame_title: this.$i18n.get('instruction_select_files_to_attach_to_item'),
frame_button: this.$i18n.get('label_attach_to_item'), frame_button: this.$i18n.get('finish'),
}, },
nonce: this.item.nonces ? this.item.nonces['update-post_' + this.item.id] : null, nonce: this.item.nonces ? this.item.nonces['update-post_' + this.item.id] : null,
relatedPostId: this.itemId, relatedPostId: this.itemId,
@ -1670,6 +1670,7 @@ export default {
onSave: () => { onSave: () => {
// Fetch current existing attachments // Fetch current existing attachments
this.shouldLoadAttachments = !this.shouldLoadAttachments; this.shouldLoadAttachments = !this.shouldLoadAttachments;
console.log('opa')
} }
} }
); );

View File

@ -2,45 +2,6 @@ export default {
// AttachmentControl: requires upload of new files and accepts multiple files // AttachmentControl: requires upload of new files and accepts multiple files
attachmentControl: wp.customize.MediaControl.extend({ attachmentControl: wp.customize.MediaControl.extend({
/**
* Set up gallery toolbar.
*
* @return {void}
*/
galleryToolbar() {
this.toolbar.set(
new wp.media.view.Toolbar( {
controller: this,
items: {
insert: {
style: 'primary',
text: wp.media.view.l10n.update,
priority: 80,
requires: { library: true },
/**
* @fires wp.media.controller.State#select
*/
click() {
const controller = this.controller,
state = controller.state();
controller.close();
state.trigger(
'select',
state.get( 'library' )
);
// Restore and reset the default state.
controller.setState( controller.options.state );
controller.reset();
},
},
},
} )
);
},
/** /**
* Create a media modal select frame, and store it so the instance can be reused when needed. * Create a media modal select frame, and store it so the instance can be reused when needed.
*/ */
@ -54,6 +15,9 @@ export default {
wp.media.model.settings.post.id = parseInt(this.params.relatedPostId); wp.media.model.settings.post.id = parseInt(this.params.relatedPostId);
this.frame = wp.media({ this.frame = wp.media({
button: {
text: this.params.button_labels.frame_button
},
states: [ states: [
new wp.media.controller.Library({ new wp.media.controller.Library({
title: this.params.button_labels.frame_title, title: this.params.button_labels.frame_title,
@ -64,7 +28,6 @@ export default {
posts_per_page: -1, posts_per_page: -1,
query: true query: true
}), }),
toolbar: 'main-gallery',
autoSelect: true, autoSelect: true,
sortable: true, sortable: true,
filterable: 'unattached', filterable: 'unattached',
@ -72,8 +35,6 @@ export default {
] ]
}).open(); }).open();
this.frame.on( 'toolbar:create:main-gallery', this.galleryToolbar, this.frame );
this.frame.$el.addClass( 'tainacan-item-attachments-modal' ); this.frame.$el.addClass( 'tainacan-item-attachments-modal' );
this.frame.$el['tainacan-document-id'] = this.params.document; this.frame.$el['tainacan-document-id'] = this.params.document;
this.frame.$el['tainacan-thumbnail-id'] = this.params.thumbnailId; this.frame.$el['tainacan-thumbnail-id'] = this.params.thumbnailId;