-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Allow contents of Paragraph to be "connected" to a meta custom field #53247
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
Changes from 1 commit
77047c3
ff12248
514a068
66a9aef
5fbf21c
a493bb1
7575b40
f8ee25e
39cb931
fa042ca
64a5f03
d7fccec
0b52159
2014934
52b4a58
cbec419
c29d885
9f0d851
1c65e74
8638dff
88dd0b5
81f9c67
60fa061
713c6df
e80effe
7640a60
f0bcb0f
6a2785f
4408e69
5cd3d22
6d00a9b
367ee0c
a45e464
84f2a08
49d5cb6
414b322
92c3cd9
ba713a4
a5b9e3b
a0bd2ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
| /** | ||
| * Meta Custom Source | ||
| * | ||
| * @package gutenberg | ||
| */ | ||
|
|
||
| return array( | ||
| 'name' => 'meta', | ||
| 'apply_source' => function ( $block_content, $block_instance, $meta_field, $attribute_config ) { | ||
| $meta_value = get_post_meta( $block_instance->context['postId'], $meta_field, true ); | ||
| $p = new WP_HTML_Tag_Processor( $block_content ); | ||
| $found = $p->next_tag( | ||
| array( | ||
| // TODO: build the query from CSS selector. | ||
| 'tag_name' => $attribute_config['selector'], | ||
| ) | ||
| ); | ||
| if ( ! $found ) { | ||
| return $block_content; | ||
| } | ||
| $tag_name = $p->get_tag(); | ||
| $markup = "<$tag_name>$meta_value</$tag_name>"; | ||
| $p2 = new WP_HTML_Tag_Processor( $markup ); | ||
| $p2->next_tag(); | ||
| $names = $p->get_attribute_names_with_prefix( '' ); | ||
| foreach ( $names as $name ) { | ||
| $p2->set_attribute( $name, $p->get_attribute( $name ) ); | ||
| } | ||
|
|
||
| return $p2 . ''; | ||
michalczaplinski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| "description": "Start with the basic building block of all narrative.", | ||
| "keywords": [ "text" ], | ||
| "textdomain": "default", | ||
| "usesContext": [ "postId" ], | ||
|
Contributor
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 wonder whose responsibility is it to do that. In other words, the block is not using the "postId" explicitly, so why add the "useContext" here. The "connection framework" should inject/filter this somehow.
Contributor
Author
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. Do you mean that in the context of Core blocks or custom blocks or both?
Contributor
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. both
Contributor
Author
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. OK! For now, I think that for core blocks this is fine. But you're right that for custom blocks we'll have to come up with a proper mechanism here. Are you all right with that?
Contributor
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. Yeah I think it's part of the definition of a "custom source" to say which change it needs to make to block registration. I think we should use it for both core and third-party blocks but yeah it's fine to start without it.
Member
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. For now, you could update
Contributor
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. Even though this is the first implementation and custom blocks are not supported yet, I believe it'd be better to start creating mechanisms that would work for both if possible. Mainly because we already know we will want to support that in the future.
Contributor
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. Coming in a bit late here. The current work on partial syncing (#54233) is using the store actions/selectors for attributes to inject/update values, but it might be difficult to pull this off if block context is being used for custom fields, as I believe it uses react context in JS. While they're still proofs of concepts, the current work for custom fields/partial syncing does need to remain compatible, so it might be good to explore ways to read/write custom field values in the editor soon though so that we have a clear idea of the problems that need to be solved. |
||
| "attributes": { | ||
| "align": { | ||
| "type": "string" | ||
|
|
@@ -28,6 +29,14 @@ | |
| "direction": { | ||
| "type": "string", | ||
| "enum": [ "ltr", "rtl" ] | ||
| }, | ||
| "connections": { | ||
| "type": "object", | ||
| "attributes": { | ||
| "content": { | ||
| "source": "meta" | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "supports": { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.