Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images: Adding images to a post doesn't also attach it #1586

Closed
jasmussen opened this Issue Jun 29, 2017 · 9 comments

Comments

Projects
None yet
9 participants
@jasmussen
Copy link
Contributor

jasmussen commented Jun 29, 2017

This can cause theme issues.

@aduth

This comment has been minimized.

Copy link
Member

aduth commented Aug 18, 2017

Should be fixed as of #1967

@aduth aduth closed this Aug 18, 2017

@rachelmcr

This comment has been minimized.

Copy link
Contributor

rachelmcr commented Oct 13, 2017

I tested publishing a photo post in Gutenberg 1.4.0 and the photo wasn't attached. Video of my publishing flow and other details here: https://test.wordpress.com/2017/10/13/image-posting-flow-gutenberg/

@aduth aduth reopened this Oct 13, 2017

@aduth

This comment has been minimized.

Copy link
Member

aduth commented Oct 13, 2017

To clarify, this appears to be specific to drag-and-drop upload, which uses its own implementation to upload to the WordPress REST API. Uploading using the media library within Gutenberg will correctly attach the image to the post.

@aduth

This comment has been minimized.

Copy link
Member

aduth commented Oct 13, 2017

The naive answer would be to inject _wpMediaViewsL10n.settings.post.id as parent property in the media upload:

return new wp.api.models.Media().save( null, {
data: data,
contentType: false,
} );

But...

  • Something is clobbering ``_wpMediaViewsL10n.settings` at runtime and it isn't accessible after page loda
  • This ties the media upload tool to the presence of a window global, and is less predictable by its implicitness (not pure). Ideally that which calls the upload would also pass the post ID as an argument.

For drag-and-drop, that happens in the image block transform:

{
type: 'files',
isMatch( files ) {
return files.length === 1 && files[ 0 ].type.indexOf( 'image/' ) === 0;
},
transform( files ) {
return createMediaFromFile( files[ 0 ] )
.then( ( media ) => createBlock( 'core/image', {
id: media.id,
url: media.source_url,
} ) );
},
},

This ties into #2473, where blocks (let alone transforms) don't currently have easy access to post state.

@mrleemon

This comment has been minimized.

Copy link
Contributor

mrleemon commented Jan 17, 2018

Is the "Attached to this post" idea going to be deprecated with Gutenberg? I'm asking this because some custom post types I've seen out there (Portfolio, Events, Ads, etc...) use this to just display images attached to posts.

@karmatosed karmatosed added this to the Merge Proposal milestone Jan 25, 2018

@bobbingwide

This comment has been minimized.

Copy link
Contributor

bobbingwide commented Mar 1, 2018

Please can someone give this bug the attention it deserves? It's a backward compatibility issue.

@bobbingwide

This comment has been minimized.

Copy link
Contributor

bobbingwide commented Mar 2, 2018

I’d just like to point out that this problem occurs when using the Upload button in the Image block.

@danielbachhuber

This comment has been minimized.

Copy link
Member

danielbachhuber commented Apr 11, 2018

@joemcgill Did you get anywhere on this or can I help out with it?

@joemcgill

This comment has been minimized.

Copy link
Contributor

joemcgill commented Apr 11, 2018

@danielbachhuber haven’t looked at it yet. Was hoping to have a go at it soon, but feel free.

@danielbachhuber danielbachhuber self-assigned this Apr 11, 2018

@karmatosed karmatosed modified the milestones: Merge Proposal, Merge Proposal: Media Apr 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.