Skip to content

Add option for themes to configure block styles#16532

Closed
jorgefilipecosta wants to merge 2 commits intomasterfrom
add/option-for-themes-to-configure-inline-styles
Closed

Add option for themes to configure block styles#16532
jorgefilipecosta wants to merge 2 commits intomasterfrom
add/option-for-themes-to-configure-inline-styles

Conversation

@jorgefilipecosta
Copy link
Copy Markdown
Member

@jorgefilipecosta jorgefilipecosta commented Jul 11, 2019

Description

Depends on: #16465

This PR extends the work done in #16465 . to allow themes to set the default styles applied to a block.

How has this been tested?

I went to functions.php of the currently enabled theme.
I pasted the following code:

function setup_default_block_styles() {
	add_theme_support(
		'editor-default-block-styless',
		array(
			'core/quote'     => 'large',
			'core/pullquote' => 'solid-color',
		)
	);
}

add_action( 'after_setup_theme', 'setup_default_block_styles' );

I created a new quote and a new pullquote I verified the default styles were large and solid color respectively.

@jorgefilipecosta jorgefilipecosta added [Feature] Theme Style Variations Related to style variations provided by block themes [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. labels Jul 11, 2019
@jorgefilipecosta jorgefilipecosta force-pushed the add/option-for-themes-to-configure-inline-styles branch from 80d96cb to a97655c Compare July 11, 2019 10:52
@chrisvanpatten
Copy link
Copy Markdown
Contributor

Can I suggest naming it editor-default-block-styles? “Auto apply” is slightly confusing, vs “default”.

@youknowriad youknowriad requested a review from mtias July 12, 2019 14:18
@jorgefilipecosta jorgefilipecosta changed the title Add option for themes to configure inline styles Add option for themes to configure block styles Aug 19, 2019
@jorgefilipecosta jorgefilipecosta force-pushed the add/option-for-themes-to-configure-inline-styles branch 2 times, most recently from 3635719 to 5261961 Compare September 3, 2019 13:53
@jorgefilipecosta
Copy link
Copy Markdown
Member Author

Hi @chrisvanpatten, your suggestion was applied.
I think this PR should be ready for a review.

function gutenberg_add_auto_apply_block_styles_setting( $settings ) {
$auto_apply_styles = current( (array) get_theme_support( 'editor-default-block-styles' ) );
if ( false !== $auto_apply_styles ) {
$settings['themeAutoApplyStyles'] = $auto_apply_styles;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if it's too late to rename that but I think we should be consistent with naming between __experimentalPreferredBlockStyles editor-default-block-styles and themeAutoApplyStyles .

Maybe __experimentalPreferredBlockStyles, editor-preferred-block-styles and preferredBlockStyles

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hi @youknowriad your suggestion was applied 👍

@jorgefilipecosta jorgefilipecosta force-pushed the add/option-for-themes-to-configure-inline-styles branch from 5261961 to 42200b5 Compare January 29, 2020 17:11
@jorgefilipecosta jorgefilipecosta force-pushed the add/option-for-themes-to-configure-inline-styles branch from 42200b5 to adf918a Compare January 29, 2020 20:06
* @return array Filtered editor settings.
*/
function gutenberg_add_preferred_block_styles_setting( $settings ) {
$preferred_block_styles = current( (array) get_theme_support( 'editor-preferred-block-styles' ) );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason for everything else being experimental and not this: editor-preferred-block-styles

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The reason was that while I expected editor-preferred-block-styles to be the way themes set the default styles, I was not totally confident in the way we pass the settings to the block editor. We have the user preference and the theme preference, we pass a single default (join of both settings). Depending on the UI we may need to pass the user value and the theme value (e.g: if we want to show the default if the user resets its setting). As the block styles UI, did not receive much attention I thought it would be good to keep the options open.
But we can make editor-preferred-block-styles experimental, or stabilize the javascript settings given that an additional time passed and until now we did not face problems. Any thoughts on this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The reason was that while I expected editor-preferred-block-styles to be the way themes set the default styles

Do you think the global styles work (theme.json) or the block-features proposal could change that too?

@jorgefilipecosta
Copy link
Copy Markdown
Member Author

Closing this PR until we defined a way to offer something equivalent with global styles.

@youknowriad youknowriad deleted the add/option-for-themes-to-configure-inline-styles branch March 23, 2020 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Theme Style Variations Related to style variations provided by block themes [Feature] Themes Questions or issues with incorporating or styling blocks in a theme.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants