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

Fix align support in block themes #136

Merged
merged 1 commit into from
Oct 8, 2021

Conversation

tomusborne
Copy link
Owner

@tomusborne tomusborne commented Oct 7, 2021

Closes #87

Previously we were checking get_theme_support( 'align-wide' ) to see if we should include the wide/full alignment options in the Container block.

However, block-based themes don't use add_theme_support() (https://fullsiteediting.com/lessons/global-styles/#h-layout-and-content-width), so this check was failing for them.

This PR ditches the get_theme_support() check and uses getBlockSupport() (https://github.com/WordPress/gutenberg/blob/1da217e8a57803e2c9183316cdef3d09c618ffcb/packages/blocks/src/store/selectors.js#L264) with an empty block name and true as the default value. This seems to allow us to artificially set support for align to true only when we need it.

It should:

  1. Show the alignment option in the toolbar for "classic" themes using add_theme_support() (GeneratePress)
  2. Show the alignment option in the toolbar for block-based themes (https://wordpress.org/themes/tt1-blocks/)
  3. Not show the alignment option for "classic" themes if add_theme_support( 'align-wide' ) is not set
  4. Not show the alignment option for block-based themes if the layout options aren't set in theme.json: https://github.com/WordPress/theme-experiments/blob/master/tt1-blocks/theme.json#L111-L114

It would obviously be easier if we could set the align supports option to true in block registration, but then we would:

  1. Have wide/full alignment for grid items which isn't possible
  2. Not have control over where in the toolbar the option appears

@tomusborne tomusborne added bug Bugs, unexpected and weird behaviors priority: high labels Oct 7, 2021
Copy link
Contributor

@JeanPaiva JeanPaiva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good.

@tomusborne tomusborne merged commit af4b79f into release/1.4.0 Oct 8, 2021
@tomusborne tomusborne deleted the improve-align-support-check branch October 8, 2021 15:57
@bradhogan
Copy link

What was the solution to this? I'm also running into an issue when I have theme.json and add_theme_support( 'align-wide' ); with the align wide and full options not appearing in the editor.

@markdavies
Copy link

I'm still seeing this issue as well. add_theme_support( 'align-wide' ); has no effect for image blocks

@flmuel
Copy link

flmuel commented Apr 11, 2022

The theme.json overrides features added via add_theme_support(). This is known and ok. But strangely the theme.json overwrites also the function "align-wide" although this is not defined in the schema or can't be configured there at all.

The problem lies in the merging of the settings. The error is in the function "get_theme_data()" in the "WP_Theme_JSON_Resolver" class -> https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-theme-json-resolver.php#L195 where "Theme Support" settings are mapped to the SCHEMA. So "align-wide" and possibly other features are simply removed here.
Obviously, only these (false) merged settings from get_merged_data() are then used for the editor.


Long story short -> you have to define minimum "contentSize" child attribute of "layout" in theme.json to display the "Full width" button in Align...
Then you also don't have to add theme support for "align-wide".

@Zsolt-R
Copy link

Zsolt-R commented Feb 10, 2023

This problem reappeared in Gutenberg version 15.1.0
With a clean installation, created a test child theme containing:

  • style.css
  • index.php
  • functions.php with add_theme_support( 'align-wide' );

Create a new page and insert a cover block and you have the align wide/full controls, then add a basic theme.json with only this content:
{ "$schema": "https://schemas.wp.org/trunk/theme.json", "version": 2, "settings": { "layout": { "contentSize": "650px", "wideSize": "1200px" } } }
the align wide/full disappears from all the blocks that had alignments.

@strarsis
Copy link

strarsis commented Feb 28, 2023

@Zsolt-R: +1, same issue again with latest Gutenberg!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs, unexpected and weird behaviors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants