-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Sync packages for WP 6.9 beta 3 #10453
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,9 +66,12 @@ function render_block_core_archives( $attributes ) { | |
| $show_label = empty( $attributes['showLabel'] ) ? ' screen-reader-text' : ''; | ||
|
|
||
| $block_content = '<label for="' . $dropdown_id . '" class="wp-block-archives__label' . $show_label . '">' . esc_html( $title ) . '</label> | ||
| <select id="' . $dropdown_id . '" name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"> | ||
| <select id="' . esc_attr( $dropdown_id ) . '" name="archive-dropdown"> | ||
| <option value="">' . esc_html( $label ) . '</option>' . $archives . '</select>'; | ||
|
|
||
| // Inject the dropdown script immediately after the select dropdown. | ||
| $block_content .= block_core_archives_build_dropdown_script( $dropdown_id ); | ||
|
|
||
| return sprintf( | ||
| '<div %1$s>%2$s</div>', | ||
| $wrapper_attributes, | ||
|
|
@@ -106,6 +109,55 @@ function render_block_core_archives( $attributes ) { | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Generates the inline script for an archives dropdown field. | ||
| * | ||
| * @since 6.9.0 | ||
| * | ||
| * @param string $dropdown_id ID of the dropdown field. | ||
| * | ||
| * @return string Returns the dropdown onChange redirection script. | ||
| */ | ||
| function block_core_archives_build_dropdown_script( $dropdown_id ) { | ||
| ob_start(); | ||
|
|
||
| $exports = array( $dropdown_id, home_url() ); | ||
| ?> | ||
| <script> | ||
| ( ( [ dropdownId, homeUrl ] ) => { | ||
| const dropdown = document.getElementById( dropdownId ); | ||
| function onSelectChange() { | ||
| setTimeout( () => { | ||
| if ( 'escape' === dropdown.dataset.lastkey ) { | ||
| return; | ||
| } | ||
| if ( dropdown.value ) { | ||
| location.href = dropdown.value; | ||
| } | ||
| }, 250 ); | ||
| } | ||
| function onKeyUp( event ) { | ||
| if ( 'Escape' === event.key ) { | ||
| dropdown.dataset.lastkey = 'escape'; | ||
| } else { | ||
| delete dropdown.dataset.lastkey; | ||
| } | ||
| } | ||
| function onClick() { | ||
| delete dropdown.dataset.lastkey; | ||
| } | ||
| dropdown.addEventListener( 'keyup', onKeyUp ); | ||
| dropdown.addEventListener( 'click', onClick ); | ||
| dropdown.addEventListener( 'change', onSelectChange ); | ||
| } )( <?php echo wp_json_encode( $exports, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?> ); | ||
| </script> | ||
| <?php | ||
| return wp_get_inline_script_tag( | ||
| trim( str_replace( array( '<script>', '</script>' ), '', ob_get_clean() ) ) . | ||
| "\n//# sourceURL=" . rawurlencode( __FUNCTION__ ) | ||
| ); | ||
|
Comment on lines
+155
to
+158
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. Should we use
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. Yes, although it's not important. It can be done in a follow-up PR to Gutenberg. |
||
| } | ||
|
|
||
| /** | ||
| * Register archives block. | ||
| * | ||
|
|
||
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.
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.
What's the objective reason to remove the blank line? It passes the coding standard checks, and other PHPDocs in the same file have had the same blank line for years
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.
I concur with @priethor here, no need to remove that line as most (all?) cases here include the line spacing (and at least for me makes it easier to read those docs/comments).
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.
It's not a blocker but as per WordPress Inline Documentation Standards for PHP, there should not be an extra line between
@paramand@returntags.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.
@jeffpaul In that case we should update the PHPCS document.
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.
This can be done in a follow-up PR for Gutenberg, along with the change mentioned below.
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.
Agreed that any such change should be done in Gutenberg, starting with updating the PHPCS rules to match the coding standards.