-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Gallery: Support for ID-less shortcode #3852
Conversation
One thing to consider is that the conversion process commits image IDs to the block’s attributes. This effectively makes the block static, a departure from the behavior of the original shortcode, which was dynamic. In other words, if some agent somewhere modifies which media items are attached to the post, this Gallery block will not reflect those changes. The behavior could be made entirely dynamic by not committing the attached images to the attributes (e.g., Latest Posts), but there are trade-offs to make.
|
We don't have a way to create a dynamic gallery from scratch, so at the moment converting an old one should make it static. That said, it might be worth allowing this as an option in the inspector — "load all images attached to this post". Toggling it makes the block save |
Sounds good. If it's small enough I'll fit it in this PR.
|
blocks/library/gallery/block.js
Outdated
@@ -262,4 +310,40 @@ class GalleryBlock extends Component { | |||
} | |||
} | |||
|
|||
export default GalleryBlock; | |||
// FIXME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data module might help here since it's a canonical way to access the WP client state #3832
But we can't assume the post is present, I'm thinking the gallery block should work for site building later and we don't have a post necessarily. This option should be only available if we detect an "editor" state and a "post Id".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had started to review this and should’ve connected the dots. Thanks, this sounds like a good way to try the module.
can’t assume […] site building […] only if we detect
Yes, great points!
ae847f5
to
1513e64
Compare
1513e64
to
145eccc
Compare
Rewritten using the newest
|
Flagging as
This presents the same scope of problem as described in #4522 (comment)
In this particular case, the current I'm not opposed to changing this behavior. I only want to highlight that we need to make it a deliberate, communicated decision. One idea: user-test this change with a couple of users to get their opinion on whether this is a significant enough change to merit more UX. |
Thanks for the perspective, @danielbachhuber. My very personal opinion is that the concept of attaching media to a post is just one of those very weird WordPress intricacies that should, one way or another, be deprecated at some point. By this I mean no disrespect to those using In a Gutenberg-based future, here's how I see things: (editing limitations) Some users just wanted a nice way to construct a gallery whose items may change in the future, so they relied on the automatic media attachment feature. For these, a Gallery block hopefully offers a much better experience. (backend limitations) Some users may be doing things in the backend: trigger changes to attachments based on certain updates, add/remove attachments via the REST API, etc. For these, the editing interface won't cut it, obviously. However, it's fair to say the API will catch up with blocks: I'd expect that we'll be able to treat blocks in a post as resources, whether at the lowest level (direct manipulation of the attributes object and inner HTML) or a block-provided abstraction (for a Gallery: add image, remove image). Until this beautiful day comes, I can understand that we want to support dynamic galleries, though. I have no strong opinion here. If the way forward is support dynamic behavior, please express yourselves. :) Note that dynamic blocks currently can't handle their inner HTML, only comment attributes (ref), and that kind of support isn't ready for primetime. This means we can't have a block whose static or dynamic character depends on its attributes. Thus, if we want to support dynamic galleries now, the solution I see is creating a new block type just for dynamic galleries. The final UX for all of this would be tricky to get right, though (would we burden the user with the question of whether they want their gallery to be static or dynamic? what does that mean for most?). |
I'd love to hear @westonruter's opinion on this too. |
I'll note that when we added shortcode support to the Text widget one of the key use cases for it was to allow for a Text widget to have a |
@westonruter: That's good insight, thanks, especially the expectations around the Text widget.
Good point, although, at the same time, how could we avoid creating confusion between the two scenarios:
This sort of challenge makes me cautious about trying to fit everything into the core Gallery block. Similar questions: when in "dynamic" ( |
You're right. It is a “power user” feature, that is, a hack. But it's a key use case that is depended on.
I think we're getting closer into a site customization context here, where we're getting into territory that is outside of specifically a post context. Clearly the gallery shortcode in this case allows for a variable post context to draw from. This could also be the case for the Text widget generally, as shortcodes used in the Text widget could be referencing postmeta for the current queried post and thus also be variable as the same widget is displayed on different pages. In site customization, I expect there is going to be a need to identify certain blocks that get re-used across multiple/all templates of a site. For example, there should be header blocks and sidebar blocks that contain nested blocks inside of them. These nested blocks may need to vary depending on which URL they are being rendered on. For instance, a nav menu has the class names render differently depending on the URL that it is rendered on (e.g. so items can be styled as the “current” page or not). So I think the question (and problem) is somewhat wider than just the gallery. It's the local block vs global block problem. I don't know of a user-friendly way to present this to the user per se, but what if there was a sort of “HOC” container block for post context? Maybe this could be presented as a sidebar control instead of a block container instead, but there could be an advanced way to specify the context that a specific block should be rendered in. By default it should be the current post being edited. But it could also be set to the current post being viewed. Maybe that idea could be combined with reusable blocks to implement the |
Per the WP Codex, the [gallery] shortcode should be supported when no IDs are provided: > The default behavior, if no ID is specified, is to display images > attached to the current post. -- https://codex.wordpress.org/Gallery_Shortcode
145eccc
to
4f89d8f
Compare
This is good food for thought for the future. I don't necessarily see context-switching container blocks, but I do see some blocks as being able to (and offering to) operate in different contexts. In any case, as a way to move this PR forward, one thing I can do is allow dynamic blocks to fall back to static content on the server: https://gist.github.com/mcsf/573fd7c42943f89c44ab31efe29d1a81 In short: if a block is server-side registered with a function render_block_core_gallery( $attributes ) {
return $attributes['useAttachedImages'] ? '[gallery]' : null;
} If the piece described above is something we're OK adding, then we need to agree on an acceptable UX for the MVP of this dual gallery block. Some approaches:
|
Looping @melchoyce in here as this is dipping into the Customization focus. My own feelings are based on @mscf's summary my preference is:
|
I am removing design feedback label as it does have that. |
@mcsf @karmatosed Given the intersection of today's date and the state of this pull request, I have a proposal that lets us kick this decision into the future:
Ultimately, it doesn't appear we've yet come to a "good" option, only varying degrees of worse options. I don't think this UX is important enough to try to rush a decision on. Plus, we still have aspects like #5972 to deal with. Also, based on my Swarm, @westonruter is on vacation right now so I expect any input from him would be delayed. |
What a delay on this one! I think this is a good "less bad" option. Edit: Moving the following to new issue #11551.
|
Closing. Opening #11551 instead. |
Per the WP Codex, the [gallery] shortcode should be supported when no IDs are provided:
— https://codex.wordpress.org/Gallery_Shortcode
Description
Pasting
[gallery]
with no extra attributes, namelyids
, generates a Gallery block with the post's attached media. Same goes for converting from classic post to blocks.Approach
useAttachedImages
, is added to Gallery. It defaults to false.useAttachedImages
is set to true for the generated Gallery block. (This transform kicks in when pasting shortcodes, but also when converting classic content to blocks.)useAttachedImages
as true, request information on the images attached to the current post from the core media endpoint. This request is performed viawithAPIData
.How Has This Been Tested?
[gallery]
.It should be rendered as a Gallery block comprising the images originally attached to the post.
Screenshots (jpeg or gifs if applicable):
Caveat / To fix
Types of changes
Checklist: