[wp-trac] [WordPress Trac] #53765: Media Library shows only the selected image

WordPress Trac noreply at wordpress.org
Fri Nov 12 10:18:18 UTC 2021


#53765: Media Library shows only the selected image
--------------------------+-------------------------
 Reporter:  benitolopez   |       Owner:  joedolson
     Type:  defect (bug)  |      Status:  accepted
 Priority:  normal        |   Milestone:  5.9
Component:  Media         |     Version:  5.8
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:  javascript
--------------------------+-------------------------

Comment (by szaqal21):

 I've made a lot of debug work and results are:

 Gutenberg - lines from 487 to 493 of /wp-includes/js/dist/media-utils.js
 show what exactly is going on when frame opens, selection is being setup
 after attachments.more() is done


 {{{
 attachments.more().done(function () {
       var _attachments$models;

       if (isGallery && attachments !== null && attachments !== void 0 &&
 (_attachments$models = attachments.models) !== null && _attachments$models
 !== void 0 && _attachments$models.length) {
         selection.add(attachments.models);
       }
     });
 }}}


 Classic editor - there is no call for loading more attachments on frame
 activation in /wp-includes/js/media-views.js lines 4047 - 4052


 {{{
 activate: function() {
                 this.updateSelection();
                 this.frame.on( 'open', this.updateSelection, this );

                 Library.prototype.activate.apply( this, arguments );
         },
 }}}


 only updateSelection() (called twice, don't know why) which fetches only
 featured image (if set) so library has only one attachment and more()
 isn't called as @PieWP mentioned.


 I've made those code changes:

 includes/js/media-views.js lines 4047 - 4052 - call updateSelection() only
 on frame open event


 {{{
 activate: function() {
                 this.frame.on( 'open', this.updateSelection, this );

                 Library.prototype.activate.apply( this, arguments );
         },
 }}}

 added call of more() to updateSelection() in includes/js/media-views.js
 lines 4066 - 4077


 {{{
 updateSelection: function() {
                 var selection = this.get('selection'),
                         library = this.get('library'),
                         id = wp.media.view.settings.post.featuredImageId,
                         attachment;

                 if ( '' !== id && -1 !== id ) {
                         attachment = Attachment.get( id );
                         attachment.fetch();
                 }

                 selection.reset( attachment ? [ attachment ] : [] );

                 library.more();
         }
 }}}

 and includes/js/media-views.js lines 7470 - 7475


 {{{
 updateSelection: function() {
                 var selection = this.get('selection'),
                         library = this.get('library'),
                         attachment = this.image.attachment;

                 selection.reset( attachment ? [ attachment ] : [] );

                 library.more();
         }
 }}}

 didn't noticed any unexpected behaviour in Gutenberg and Classic editor
 and everything works fine now. Perhaps it would be more elegant and
 intuitive to move more() call to activate() of ReplaceImage and
 FeatureImage views.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53765#comment:21>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list