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

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

Open
Tracked by #29506
oandregal opened this issue Aug 26, 2021 · 2 comments
Open
Tracked by #29506

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

oandregal opened this issue Aug 26, 2021 · 2 comments
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Task Issues or PRs that have been broken down into an individual action to take

Comments

@oandregal
Copy link
Member

oandregal commented Aug 26, 2021

Related #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 oandregal added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label Aug 26, 2021
@oandregal oandregal mentioned this issue Aug 26, 2021
82 tasks
@mtias mtias added the [Type] Task Issues or PRs that have been broken down into an individual action to take label Aug 26, 2021
@mtias mtias mentioned this issue Aug 27, 2021
12 tasks
@oandregal
Copy link
Member Author

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

  • themes now define layout.contentWidth and layout.wideSize which already control the visibility of the alignment controls
  • float options (left, center, right) are unaffected by the existing layout (they are always visible if the block supports it)
  • disabling alignment options per block can be confusing to users
  • we have different layout options (flow, flex) and alignments are contextual to the particular layout

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

@fabiankaegy
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

No branches or pull requests

3 participants