-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Register the block attributes server-side for blocks with support flags #24400
Changes from all commits
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 |
---|---|---|
|
@@ -5,6 +5,47 @@ | |
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Registers the style and colors block attributes for block types that support it. | ||
* | ||
* @param array $block_type Block Type. | ||
*/ | ||
function gutenberg_register_colors_support( $block_type ) { | ||
$color_support = gutenberg_experimental_get( $block_type->supports, array( '__experimentalColor' ), false ); | ||
$has_text_colors_support = is_array( $color_support ) || $color_support; | ||
$has_background_colors_support = $has_text_colors_support; | ||
$has_gradients_support = $has_text_colors_support && gutenberg_experimental_get( $color_support, array( 'gradients' ), false ); | ||
|
||
if ( ! $block_type->attributes ) { | ||
$block_type->attributes = array(); | ||
} | ||
|
||
if ( $has_text_colors_support && ! array_key_exists( 'style', $block_type->attributes ) ) { | ||
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 may be more readable if we use At first glance reading it I thought "why are we only defining the style object for text colors?", but then realized that none of the others can be supported without text color support anyways. So it still looks correct from a functionality standpoint! |
||
$block_type->attributes['style'] = array( | ||
'type' => 'object', | ||
); | ||
} | ||
|
||
if ( $has_background_colors_support && ! array_key_exists( 'backgroundColor', $block_type->attributes ) ) { | ||
$block_type->attributes['backgroundColor'] = array( | ||
'type' => 'string', | ||
); | ||
} | ||
|
||
if ( $has_text_colors_support && ! array_key_exists( 'textColor', $block_type->attributes ) ) { | ||
$block_type->attributes['textColor'] = array( | ||
'type' => 'string', | ||
); | ||
} | ||
|
||
if ( $has_gradients_support && ! array_key_exists( 'gradient', $block_type->attributes ) ) { | ||
$block_type->attributes['gradient'] = array( | ||
'type' => 'string', | ||
); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Add CSS classes and inline styles for colors to the incoming attributes array. | ||
* This will be applied to the block markup in the front-end. | ||
|
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.
Ah, yes! Good addition we missed in the last one. This makes sense to not define if it is already defined.