WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10k stars 4.02k forks source link

Default block alignment class is not in get_block_wrapper_attributes #50027

Open warudin opened 1 year ago

warudin commented 1 year ago

Description

I created a block, the settings are below in the block.json.

The block should have a full width alignment by default (mentioned here in the documentation: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/#align)

This works good in the editor. But in my render file, the get_block_wrapper_attributes() function is not outputting the align class.

The align class is only returned when I configure another block width then the one that’s in the attributes (so ‘none’ or ‘wide’). The default alignment is never returned, even after toggling another one and going back to the default alignment.

block.json:
{
    ...
    "attributes": {
        "align": {
            "type": "string",
            "default": "full"
        }
        ...
    },
    "supports": {
        "html": false,
        "align": [
            "wide",
            "full"
        ],
        ...
    },
    ...
}

Step-by-step reproduction instructions

  1. Configure a block to have a specific alignment (i.e. 'full') by adding it as a default value in attributes.align in block.json;
  2. Configure and create a PHP render template file in block.json;
  3. Use get_block_wrapper_attributes() to output the classes in the wrapper div;
  4. Add the block to the editor and leave the default alignment configured, save the editor;
  5. Check the classes being output in the front-end, the configured alignment will not be in the list that's being returned by get_block_wrapper_attributes().

Screenshots, screen recording, code snippet

No response

Environment info

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

marcoluzi commented 8 months ago

I got the same problem. Did you find a solution for that @warudin ?

colorful-tones commented 7 months ago

I would love to see this prioritized for the WordPress 6.5 release. Several issues are related, and it may be worth aggregating into a parent task.

@ndiego @gziolo, do you have any insight on the priorities here, please?

Some related issues: