Changeset 56710 for trunk/src/wp-includes/blocks/file.php
- Timestamp:
- 09/26/2023 02:20:18 PM (19 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/file.php
r56065 r56710 6 6 */ 7 7 8 if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {9 /**10 * Replaces view script for the File block with version using Interactivity API.11 *12 * @param array $metadata Block metadata as read in via block.json.13 *14 * @return array Filtered block type metadata.15 */16 function gutenberg_block_core_file_update_interactive_view_script( $metadata ) {17 if ( 'core/file' === $metadata['name'] ) {18 $metadata['viewScript'] = array( 'file:./interactivity.min.js' );19 }20 return $metadata;21 }22 add_filter( 'block_type_metadata', 'gutenberg_block_core_file_update_interactive_view_script', 10, 1 );23 }24 25 8 /** 26 * When the `core/file` block is rendering, check if we need to enqueue the ` 'wp-block-file-view` script.9 * When the `core/file` block is rendering, check if we need to enqueue the `wp-block-file-view` script. 27 10 * 28 11 * @param array $attributes The block attributes. … … 72 55 73 56 // If it uses the Interactivity API, add the directives. 74 if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN &&$should_load_view_script ) {57 if ( $should_load_view_script ) { 75 58 $processor = new WP_HTML_Tag_Processor( $content ); 76 59 $processor->next_tag(); 77 60 $processor->set_attribute( 'data-wp-interactive', '' ); 78 61 $processor->next_tag( 'object' ); 79 $processor->set_attribute( 'data-wp-bind--hidden', '!selectors.core.file.hasPdfPreview' ); 80 $processor->set_attribute( 'hidden', true ); 62 $processor->set_attribute( 'data-wp-style--display', 'selectors.core.file.hasPdfPreview' ); 81 63 return $processor->get_updated_html(); 82 64 } … … 84 66 return $content; 85 67 } 68 69 /** 70 * Ensure that the view script has the `wp-interactivity` dependency. 71 * 72 * @since 6.4.0 73 * 74 * @global WP_Scripts $wp_scripts 75 */ 76 function block_core_file_ensure_interactivity_dependency() { 77 global $wp_scripts; 78 if ( 79 isset( $wp_scripts->registered['wp-block-file-view'] ) && 80 ! in_array( 'wp-interactivity', $wp_scripts->registered['wp-block-file-view']->deps, true ) 81 ) { 82 $wp_scripts->registered['wp-block-file-view']->deps[] = 'wp-interactivity'; 83 } 84 } 85 86 add_action( 'wp_print_scripts', 'block_core_file_ensure_interactivity_dependency' ); 86 87 87 88 /**
Note: See TracChangeset
for help on using the changeset viewer.