WordPress / gutenberg

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

Allow filtering the alignment options of blocks via `theme.json` #34317

Open oandregal opened 3 years ago

oandregal commented 3 years ago

Related https://github.com/WordPress/gutenberg/issues/34316

The align options of blocks can be filtered using the block_type_metadata filter. It'd be easier for themes if they could filter those options via theme.json as we do with other settings such as units.

oandregal commented 3 years ago

Ran this by Riad and this is the context I've gathered:

I'm not sure we want to do this yet.

fabiankaegy commented 2 years ago

From my perspective, the ability to filter the alignment options of blocks via theme.json would be a significant improvement. It currently is the primary thing the blocks.registerBlockType hook in JS gets used for.

function addWideAlignmentOptions(settings, name) {
    if (name !== 'namespace/block-name') {
        return settings;
    }

    return {
        ...settings,
        attributes: {
            ...settings.attributes,
            align: {
                'wide',
                'full'
            },
        },
    };
}

addFilter(
    'blocks.registerBlockType',
    'add-wide-alignment-options',
    addWideAlignmentOptions,
);

Not having to manually filter the options but instead having a more declarative way of achieving this would reduce a lot of code that by nature is modifying settings at a relatively low level in the block API.