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

Allow heading and button in Pattern Overrides #57789

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/block-supports/pattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
* @param WP_Block_Type $block_type Block Type.
*/
function gutenberg_register_pattern_support( $block_type ) {
$pattern_support = 'core/paragraph' === $block_type->name ? true : false;
global $block_bindings_allowed_blocks;
$pattern_support = array_key_exists( $block_type->name, $block_bindings_allowed_blocks );
Comment on lines +16 to +17
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this global variable will be removed in #57742, so if this PR ships first, it might be nice to help update #57742.

Copy link
Member

Choose a reason for hiding this comment

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

Now it fails in trunk

Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in /plugins/gutenberg/lib/block-supports/pattern.php:17

Copy link
Contributor

@talldan talldan Jan 18, 2024

Choose a reason for hiding this comment

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

Fixed by #57912. I did leave a note on #57742 to say that it needs to be rebased and #57912 merged first, but I don't think the person that merged it saw that.

Guess I should've been a bit noisier 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

I just saw it 😅 I didn't realize that #57742 would break trunk once this one is merged. Thanks for the patch @talldan!

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries @michalczaplinski! Thanks for approving and merging that PR, good to get it across the line!


if ( $pattern_support ) {
if ( ! $block_type->uses_context ) {
Expand Down
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/block-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@wordpress/interactivity": "file:../interactivity",
"@wordpress/keycodes": "file:../keycodes",
"@wordpress/notices": "file:../notices",
"@wordpress/patterns": "file:../patterns",
"@wordpress/primitives": "file:../primitives",
"@wordpress/private-apis": "file:../private-apis",
"@wordpress/reusable-blocks": "file:../reusable-blocks",
Expand Down
6 changes: 5 additions & 1 deletion packages/block-library/src/block/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
store as blockEditorStore,
BlockControls,
} from '@wordpress/block-editor';
import { privateApis as patternsPrivateApis } from '@wordpress/patterns';
import { parse, cloneBlock } from '@wordpress/blocks';

/**
Expand All @@ -35,10 +36,13 @@ import { parse, cloneBlock } from '@wordpress/blocks';
import { unlock } from '../lock-unlock';

const { useLayoutClasses } = unlock( blockEditorPrivateApis );
const { PARTIAL_SYNCING_SUPPORTED_BLOCKS } = unlock( patternsPrivateApis );

function isPartiallySynced( block ) {
return (
'core/paragraph' === block.name &&
Object.keys( PARTIAL_SYNCING_SUPPORTED_BLOCKS ).includes(
block.name
) &&
!! block.attributes.metadata?.bindings &&
Object.values( block.attributes.metadata.bindings ).some(
( binding ) => binding.source.name === 'pattern_attributes'
Expand Down
2 changes: 2 additions & 0 deletions packages/patterns/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ export const PATTERN_SYNC_TYPES = {
// TODO: This should not be hardcoded. Maybe there should be a config and/or an UI.
export const PARTIAL_SYNCING_SUPPORTED_BLOCKS = {
'core/paragraph': { content: __( 'Content' ) },
'core/heading': { content: __( 'Content' ) },
'core/button': { text: __( 'Text' ) },
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it also support the URL? It is editable in the UI, but doesn't work at the moment, possibly because it's missing here.

Copy link
Member

Choose a reason for hiding this comment

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

Same with the various URL connected attributes such as rel, opening in a new tab etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I was thinking about that too. It's something that block bindings would need to support as well:
https://github.com/WordPress/gutenberg/pull/57742/files#diff-13ba237ac22cd8b66e7ec6447ae508cd6385d2e6e1e4cd1ae8f73c4bdf62136fR33

Copy link
Contributor

@SantosGuillamot SantosGuillamot Jan 16, 2024

Choose a reason for hiding this comment

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

If I am not mistaken, the URL of the button should work as well. It was included in the first pull request: link. Adding most attributes should be as easy as adding them to the relevant array, so we can try to add anything you consider relevant.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great, let's try adding them in a follow-up PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

url support was added in 585a658!

};
Loading