-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Date block: Allow connecting to Block Bindings #70585
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
Merged
Merged
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
876ec3c
Date block: Make date an explicit attribute
ockham 29ff68d
Add Post Data source for Block Bindings
ockham 484accc
Use new date attribute when rendering Date Block
ockham 82d8dd2
Add Date block's date attribute to Block Bindings
ockham 3b78d35
Rename source to core/post-data
ockham 32ffff7
Prefix source keys with post_ to avoid confusion with attributes
ockham c3b4b0c
Client-side source registration
ockham c5f37e3
Fix field names
ockham 0d87e81
Rename back to make source updates work
ockham 796e3a6
Add block deprecation
ockham d2c8134
Update variation definition
ockham 05a3f43
Add variation for publish date
ockham e3ce15d
Remove displayType attribute (from the editor)
ockham 71615a5
Show date instead of placeholder in editor for bound date attribute
ockham d403a14
Remove logic to hide modified date if it's before publish date from b…
ockham f3fb91f
Add inline comment
ockham 70c6267
Fix link insertion
ockham ea362db
Add back modified date specific class name
ockham 476fe69
Retain metadata upon block migration
ockham 05bf390
Retain modified-date class name during migration
ockham c48d577
Retain backwards compatibility
ockham eadc0a6
Comment wording
ockham b98c0a9
Prefix PHP functions with gutenberg_
ockham 9d68452
Remove now-obsolete logic to add modified-date class name
ockham 8350bca
Set date attribute to default value upon block insertion
ockham 7af2a40
Change popover header
ockham 99b426f
Document new title prop
ockham 4344ab7
Update test fixtures to include modified-date class name
ockham 25bd52c
Whitespace
ockham a806014
Use gmdate() instead of date()
ockham 34e0ed6
Update e2e test snapshots
ockham 9e01be4
Make comment wording more assertive
ockham 3ecd1d5
Make sure last-modified date isn't shown if it's before publish date
ockham 24d9a4b
Add basic unit test coverage for block PHP
ockham 421cb42
Add unit test coverage for legacy version of the block
ockham 63aeff5
Add coverage for modified date before publish date
ockham 3d4ac7c
Use tabs instead of spaces for indentation
ockham c5fed1b
Coding Standards
ockham dfdff3f
Ensure that block works on current WP versions
ockham 5edd4df
Allow arbitrary sources
ockham dca0fe4
Tweak empty return branch
ockham 665795a
Add test coverage for explicitly set date attribute
ockham d5317f2
Typo in comment
ockham 5053810
Rename date attribute to datetime
ockham 88f44f6
Add backport changelog
ockham 67864f8
Polish client-side post-data source code
ockham 89311a8
Rephrase comment to be more accurate
ockham ac94d31
Add "role": "content" to datetime attribute
ockham 57a47a5
Don't register post-data source if it already exists
ockham be1bd7c
Remove unnecessary postType context dependency
ockham f45745d
Use single line comment format
ockham 1d6d7bc
Allow transforming to different variation from block inspector
ockham bf2ecd5
Extract WPBlockBindingsSource type, use in post-data source declaration
ockham 78c58d8
Add types to other block bindings sources
ockham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| https://github.com/WordPress/wordpress-develop/pull/9299 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/70585 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| <?php | ||
| /** | ||
| * Post Data source for the block bindings. | ||
| * | ||
| * @since 6.9.0 | ||
| * @package gutenberg | ||
| * @subpackage Block Bindings | ||
| */ | ||
|
|
||
| /** | ||
| * Gets value for Post Data source. | ||
| * | ||
| * @since 6.9.0 | ||
| * @access private | ||
| * | ||
| * @param array $source_args Array containing source arguments used to look up the override value. | ||
| * Example: array( "key" => "foo" ). | ||
| * @param WP_Block $block_instance The block instance. | ||
| * @return mixed The value computed for the source. | ||
| */ | ||
| function gutenberg_block_bindings_post_data_get_value( array $source_args, $block_instance ) { | ||
| if ( empty( $source_args['key'] ) ) { | ||
| return null; | ||
| } | ||
|
|
||
| if ( empty( $block_instance->context['postId'] ) ) { | ||
| return null; | ||
| } | ||
| $post_id = $block_instance->context['postId']; | ||
|
|
||
| // If a post isn't public, we need to prevent unauthorized users from accessing the post data. | ||
| $post = get_post( $post_id ); | ||
| if ( ( ! is_post_publicly_viewable( $post ) && ! current_user_can( 'read_post', $post_id ) ) || post_password_required( $post ) ) { | ||
| return null; | ||
| } | ||
|
|
||
| if ( 'date' === $source_args['key'] ) { | ||
| return esc_attr( get_the_date( 'c', $post_id ) ); | ||
| } | ||
|
|
||
| if ( 'modified' === $source_args['key'] ) { | ||
| // Only return the modified date if it is later than the publishing date. | ||
| if ( get_the_modified_date( 'Ymdhi', $post_id ) > get_the_date( 'Ymdhi', $post_id ) ) { | ||
ockham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return esc_attr( get_the_modified_date( 'c', $post_id ) ); | ||
| } else { | ||
| return ''; | ||
ockham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Registers Post Data source in the block bindings registry. | ||
| * | ||
| * @since 6.9.0 | ||
| * @access private | ||
| */ | ||
| function gutenberg_register_block_bindings_post_data_source() { | ||
| if ( get_block_bindings_source( 'core/post-data' ) ) { | ||
| // The source is already registered. | ||
| return; | ||
| } | ||
|
|
||
| register_block_bindings_source( | ||
| 'core/post-data', | ||
| array( | ||
| 'label' => _x( 'Post Data', 'block bindings source' ), | ||
| 'get_value_callback' => 'gutenberg_block_bindings_post_data_get_value', | ||
| 'uses_context' => array( 'postId' ), | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| add_action( 'init', 'gutenberg_register_block_bindings_post_data_source' ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using
datetime(rather than justdate) as the block can still be bound to the post's publish date, which is really a timestamp that includes the time (and can be set from the block toolbar's "pencil" icon via a DateTimePicker).