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

Image Block: breaks when setting the align #17799

Closed
chiilog opened this issue Oct 7, 2019 · 5 comments
Closed

Image Block: breaks when setting the align #17799

chiilog opened this issue Oct 7, 2019 · 5 comments
Labels
[Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@chiilog
Copy link
Contributor

chiilog commented Oct 7, 2019

Describe the bug

If I set settings.attributes.align.default = 'right';, when it breaks.

To reproduce

import { addFilter } from '@wordpress/hooks';
addFilter(
    'blocks.registerBlockType',
    'my-plugin/support-default-image-align',
    ( settings, name ) => {
        if ( name !== 'core/image' ) {
            return settings;
        }
        settings.attributes.align.default = 'right';

        return settings;
    }
);

Expected behavior

I expected that set default alignments.

Screenshots

20191007172319

20191007172334

Additional context

  • Gutenberg 6.5
@chiilog chiilog changed the title Image Block: breaks when setting the arrangement Image Block: breaks when setting the align Oct 7, 2019
@swissspidy swissspidy added the [Block] Image Affects the Image Block label Oct 11, 2019
@skorasaurus
Copy link
Member

I'm able to still reproduce on Gutenberg 9.5.2.

@paaljoachim
Copy link
Contributor

@talldan Dan are you able to take a look?

Thanks.

@talldan talldan added the Needs Testing Needs further testing to be confirmed. label Feb 11, 2021
@talldan
Copy link
Contributor

talldan commented Feb 11, 2021

It worked fine for me, so not really able to help:
image-right

@chiilog Is this still happening for you?

@annezazu annezazu added [Status] Needs More Info Follow-up required in order to be actionable. and removed Needs Testing Needs further testing to be confirmed. labels Feb 26, 2021
@5n
Copy link

5n commented Mar 7, 2021

@talldan Hi, I'm also able to probably still reproduce on Gutenberg 10.1.1.
The issue seems to be that the value of default alignment is not saved in block’s markup.

If you don't set default alignment:

<!-- wp:image -->
<figure class="wp-block-image"><img alt=""/></figure>
<!-- /wp:image -->

If you set default alignment as 'right':

<!-- wp:image -->
<div class="wp-block-image"><figure class="alignright"><img alt=""/></figure></div>
<!-- /wp:image -->

It works fine for new blocks, but not for existing blocks.

@talldan
Copy link
Contributor

talldan commented Mar 8, 2021

I see, yes, changing the default alignment would invalidate existing blocks that don't have that alignment. That is the expected behavior.

I think your code would need to add a deprecation to the image block to handle that (https://developer.wordpress.org/block-editor/developers/block-api/block-deprecation/).

But how you do this would depend on why you want to align images right. That's some context that is missing in this issue.

  • If this is for a plugin, what you're trying to achieve might not be the best idea. The users images shouldn't all be unexpectedly aligned to the right without it being an explicit user action.
  • If this is for your own site or a site you manage, you probably want some kind of migration script for existing content. Otherwise you have to click through every post saving it. (Proper server-side APIs for block modification #6494)

@talldan talldan closed this as completed Mar 8, 2021
@talldan talldan added [Type] Help Request Help with setup, implementation, or "How do I?" questions. and removed [Block] Image Affects the Image Block [Status] Needs More Info Follow-up required in order to be actionable. labels Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

7 participants