Skip to content
This repository has been archived by the owner on Aug 24, 2018. It is now read-only.

Gallery Widget #120

Merged
merged 43 commits into from
Sep 19, 2017
Merged

Gallery Widget #120

merged 43 commits into from
Sep 19, 2017

Conversation

obenland
Copy link
Contributor

@obenland obenland commented May 2, 2017

obenland and others added 3 commits May 2, 2017 15:14
First pass.

Fixes #62.
Very basic, needs much more polish. And styles.
@timmyc
Copy link
Contributor

timmyc commented May 3, 2017

Looks like @westonruter already commented but I saw this too:

<br />↵<b>Notice</b>: Array to string conversion in <b>/srv/www/wordpress-develop/public_html/src/wp-content/plugins/wp-core-media-widgets/wp-includes/widgets/class-wp-widget-media.php</b> on line <b>330</b><br />↵Array

Which was resulting in some JS errors in the preview render. I added some logic to ensure we are working against an array in the preview, but agree we should maybe consider returning just the image urls needed in attachments? Not entirely sure the best thing to do.

🤞 that 905edbc also clears up the travis issues.

@timmyc
Copy link
Contributor

timmyc commented May 3, 2017

I disabled the code sniffer in a few lines as it was returning the following error about rand:

wp-includes/widgets/class-wp-widget-media-gallery.php:112:38: error - Detected forbidden query_var "orderby" of "rand". Use vip_get_random_posts() instead. (WordPress.VIP.OrderByRand.orderby_orderby)

Figured that didn't really apply here.

@westonruter
Copy link
Contributor

I disabled the code sniffer in a few lines as it was returning the following error about rand

@timmyc feel free to give the WordPress.VIP.OrderByRand.orderby_orderby error a severity of 0 in the underlying phpcs.xml.dist instead.

@westonruter
Copy link
Contributor

Cross-reference Gallery block: WordPress/gutenberg#740

/**
 * TODO fix edit button
 */
@timmyc
Copy link
Contributor

timmyc commented Aug 9, 2017

@m1tk00 - excellent, I am not getting errors in the preview anymore!! Outside of the linting issues we are having on the branch now - the following flow appears to be broken for me:

  • Create a new Gallery Widget, assign photos, finish the modal wizard
  • Click "Edit Gallery" in the widget. Note the current photos are not selected, and the modal state shown is the same as creating a new gallery.

In this scenario, I expected to be shown the same dialog state as seen when clicking the 'pencil' to edit a gallery within the editor:

add_new_post_ _wordpress_develop_ _wordpress

@m1tk00
Copy link

m1tk00 commented Aug 9, 2017

@timmyc yeah thats where I got stuck. I tried passing the data via the selected option but can't get it working

@timmyc
Copy link
Contributor

timmyc commented Aug 14, 2017

@m1tk00 so looking at how the Gutenberg Gallery block performs the operation: https://github.com/WordPress/gutenberg/blob/master/blocks/media-upload-button/index.js#L124-L141 - they hook into the onOpen event then add in the selected items at that point. Do you want to give that a try or do you want me to work on that here?

@m1tk00
Copy link

m1tk00 commented Aug 14, 2017 via email

@m1tk00
Copy link

m1tk00 commented Aug 15, 2017

@timmyc Ive managed to fix the edit button. It was calling a wrong media frame. Just pushed to the repo.

@timmyc
Copy link
Contributor

timmyc commented Aug 15, 2017

@m1tk00 I'm still having issues with the edit flow - my selections are not being shown when clicking the Edit button.

@timmyc
Copy link
Contributor

timmyc commented Aug 16, 2017

So the past 3 commits are me trying to get CI to pass :) - each time, there is an array test that seems to go 💥 like the latest:

Parse error: syntax error, unexpected T_STRING in /tmp/wpcs/WordPress/Sniffs/Arrays/CommaAfterArrayItemSniff.php on line 10

Any ideas @westonruter? I tried to re-create the issue locally and could not, then again my phpcs knowledge is limited.

@joemcgill
Copy link
Contributor

@westonruter last I checked, I don't think gallery settings from the media frame, like columns, etc, are being saved to the widget. I was going to sweep through and test each setting to see what was left.

previewContainer = control.$el.find( '.media-widget-preview' );
previewTemplate = wp.template( 'wp-media-widget-gallery-preview' );

if ( control.model.get( 'ids' ).length && ! control.model.get( 'attachemnts' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

! control.model.get( 'attachemnts' ) this looks like it can be eliminated. At least, it is misspelled.

return attachment.id !== id;
} );
this.set( {
'attachments': JSON.stringify( newAttachments ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think references to 'attachments' still needs to be eliminated.

} );
this.set( {
'attachments': JSON.stringify( newAttachments ),
'ids': _.map( newAttachments, 'id' )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this actually should be _.pluck( newAttachments, 'id' ) not map.

@westonruter
Copy link
Contributor

I'm working on some improvements to the rendering and syncing of the gallery settings.


mediaFrameProps = control.mapModelToMediaFrameProps( control.model.toJSON() );
if ( mediaFrameProps.size ) {
control.displaySettings.set( 'size', mediaFrameProps.size );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be used?


mediaFrameProps = control.mapModelToMediaFrameProps( control.model.toJSON() );
if ( mediaFrameProps.size ) {
control.displaySettings.set( 'size', mediaFrameProps.size );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be used?

@westonruter
Copy link
Contributor

@joemcgill there's one key thing thing left before I think we can call this ready to merge: customizations.

When you have selected images for a gallery, you then see something like this:

image

If you try supplying a caption then:

image

And then it update, there is no changes made because there is no attachments in the model there is nowhere for the customizations to go. Normally in the post editor when you edit a caption it then gets written back to the underlying attachment. However, in the case of media widgets this is blocked entirely with this logic:

// Disable syncing of attachment changes back to server (except for deletions). See <https://core.trac.wordpress.org/ticket/40403>.
defaultSync = wp.media.model.Attachment.prototype.sync;
wp.media.model.Attachment.prototype.sync = function( method ) {
	if ( 'delete' === method ) {
		return defaultSync.apply( this, arguments );
	} else {
		return $.Deferred().rejectWith( this ).promise();
	}
};
mediaFrame.on( 'close', function onClose() {
	wp.media.model.Attachment.prototype.sync = defaultSync;
});

It seems that for the Gallery widget we must remove this logic or else a user will not be able to modify the image attributes.

This passes all of the gallery properties as shortcode atts when
rendereing the gallery on the front-end.
@joemcgill
Copy link
Contributor

@westonruter I was looking at that syncing logic yesterday and agree with you that in this context, captions should be able to be synced back to the underlying attachment. Your updates to the syncing of props between the widget control and the media frame seem to fix the issues I had noticed but the gallery attributes weren't being used to render the gallery shortcode on the front end, so I pushed another quick commit to resolve that issue.

Will do some more testing, but other than the caption issue, things are looking good from my end. Just a note that captions are a bit tricky because some themes disregard captions when they render galleries.

@westonruter
Copy link
Contributor

@joemcgill excellent, thanks. Once you merge this PR then we'll release a new version of the feature plugin to get out to testers for next week prior to core merge.

@joemcgill
Copy link
Contributor

@westonruter Got a chance to this again after e5ee972, and captions updates are now saving back to the model correctly. Going to go ahead and merge so we can get this into more hands. Nice work 🎉

@joemcgill joemcgill merged commit cec2c4f into master Sep 19, 2017
@westonruter
Copy link
Contributor

Great work everyone!

@westonruter westonruter deleted the add/gallery-widget branch September 19, 2017 06:21
@westonruter
Copy link
Contributor

The plugin auto-deployed to WordPress.org so it is now available for all to test: https://wordpress.org/plugins/wp-core-media-widgets/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants