Skip to content

Commit

Permalink
Correct experimental BC comments and tweak flow
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Mar 31, 2023
1 parent 7e7bf1c commit 3346b9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
25 changes: 12 additions & 13 deletions lib/class-wp-duotone-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,18 @@ private static function get_selector( $block_name ) {
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name );

if ( $block_type && property_exists( $block_type, 'supports' ) ) {
// Backwards compatibility for color.__experimentalDuotone. This will
// have priority over filter.duotone support. Unfortunately we can't
// prefer filter.duotone because it gets set when __experimentalDuotone
// is set via a block_type_metadata_settings hook. It shouldn't be too
// much of a problem because I would expect consumers to not use both
// at the same time.
// Backwards compatibility with `supports.color.__experimentalDuotone`
// is provided via the `block_type_metadata_settings` filter. If
// `supports.filter.duotone` has not been set and the experimental
// property has been, the experimental property value is copied into
// `supports.filter.duotone`.
$duotone_support = _wp_array_get( $block_type->supports, array( 'filter', 'duotone' ), false );
if ( ! $duotone_support ) {
return null;
}

// If the experimental duotone support was set, that value is to be
// treated as a selector and requires scoping.
$experimental_duotone = _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), false );
if ( $experimental_duotone ) {
$root_selector = wp_get_block_css_selector( $block_type );
Expand All @@ -289,13 +295,6 @@ private static function get_selector( $block_name ) {
: $root_selector;
}

// Support flag `filter.duotone` will be populated from the previous
// `color.__experimentalDuotone` support via block_type_metadata_settings filter.
$duotone_support = _wp_array_get( $block_type->supports, array( 'filter', 'duotone' ), false );
if ( ! $duotone_support ) {
return null;
}

// Regular filter.duotone support uses filter.duotone selectors with fallbacks.
return wp_get_block_css_selector( $block_type, array( 'filter', 'duotone' ), true );
}
Expand Down
33 changes: 16 additions & 17 deletions packages/block-editor/src/hooks/duotone.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,22 @@ const withDuotoneStyles = createHigherOrderComponent(
const blockType = getBlockType( props.name );

if ( blockType ) {
// Backwards compatibility for color.__experimentalDuotone. This will
// have priority over filter.duotone support. Unfortunately we can't
// prefer filter.duotone because it gets set when __experimentalDuotone
// is set via a block_type_metadata_settings hook. It shouldn't be too
// much of a problem because I would expect consumers to not use both
// at the same time.
// Backwards compatibility for `supports.color.__experimentalDuotone`
// is provided via the `block_type_metadata_settings` filter. If
// `supports.filter.duotone` has not been set and the
// experimental property has been, the experimental property
// value is copied into `supports.filter.duotone`.
const duotoneSupport = getBlockSupport(
blockType,
'filter.duotone',
false
);
if ( ! duotoneSupport ) {
return null;
}

// If the experimental duotone support was set, that value is
// to be treated as a selector and requires scoping.
const experimentalDuotone = getBlockSupport(
blockType,
'color.__experimentalDuotone',
Expand All @@ -330,17 +340,6 @@ const withDuotoneStyles = createHigherOrderComponent(
: rootSelector;
}

// Support flag `filter.duotone` will be populated from the previous
// `color.__experimentalDuotone` support via block_type_metadata_settings filter.
const duotoneSupport = getBlockSupport(
blockType,
'filter.duotone',
false
);
if ( ! duotoneSupport ) {
return null;
}

// Regular filter.duotone support uses filter.duotone selectors with fallbacks.
return getBlockCSSSelector( blockType, 'filter.duotone', {
fallback: true,
Expand Down

0 comments on commit 3346b9a

Please sign in to comment.