-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Migrate existing theme supports to configure the editor to theme.json configs #24761
Changes from all commits
442b296
eafbb8d
2c911ae
cc0465e
cb501c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,9 @@ | |
"features": { | ||
"typography": { | ||
"dropCap": false | ||
}, | ||
"colors": { | ||
"custom": true | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,13 @@ import { useSelect } from '@wordpress/data'; | |
*/ | ||
import { useBlockEditContext } from '../block-edit'; | ||
|
||
const deprecatedFlags = { | ||
'colors.custom': ( settings ) => | ||
settings.disableCustomColors === undefined | ||
? undefined | ||
: ! settings.disableCustomColors, | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where we say which existing block setting maps to which feature path (backward compatibility for block editor settings) |
||
|
||
/** | ||
* Hook that retrieves the setting for the given editor feature. | ||
* It works with nested objects using by finding the value at path. | ||
|
@@ -28,22 +35,23 @@ import { useBlockEditContext } from '../block-edit'; | |
*/ | ||
export default function useEditorFeature( featurePath ) { | ||
const { name: blockName } = useBlockEditContext(); | ||
const path = `__experimentalFeatures.${ featurePath }`; | ||
|
||
const setting = useSelect( | ||
( select ) => { | ||
const { getBlockSupport } = select( 'core/blocks' ); | ||
|
||
const blockSupportValue = getBlockSupport( blockName, path ); | ||
if ( blockSupportValue !== undefined ) { | ||
return blockSupportValue; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this hook should concern itself with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has introduced a regression by which the dropCap control is no longer shown for paragraph #24930 This is also related to this conversation. I think we should merge the fix above so it makes it to this week's release, and then we can figure out how to settle the info coming from block.json, core's theme.json, and theme's theme.json. |
||
|
||
const path = `__experimentalFeatures.${ featurePath }`; | ||
const { getSettings } = select( 'core/block-editor' ); | ||
const settings = getSettings(); | ||
|
||
const deprecatedSettingsValue = deprecatedFlags[ featurePath ] | ||
? deprecatedFlags[ featurePath ]( settings ) | ||
: undefined; | ||
|
||
return get( getSettings(), path ); | ||
if ( deprecatedSettingsValue !== undefined ) { | ||
return deprecatedSettingsValue; | ||
} | ||
return get( settings, path ); | ||
}, | ||
[ blockName, path ] | ||
[ blockName, featurePath ] | ||
); | ||
|
||
return setting; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where we added the backward compatibility support for the deprecated theme support flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the global features config is empty the previous condition will return:
And in that case, we will not pass the flag value. Should we handle this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed.