Changeset 61009 for trunk/src/wp-includes/blocks/file.php
- Timestamp:
- 10/21/2025 07:11:53 AM (3 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/blocks/file.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/file.php
r59079 r61009 11 11 * @since 5.8.0 12 12 * 13 * @param array $attributes The block attributes. 14 * @param string $content The block content. 15 * @param WP_Block $block The parsed block. 13 * @param array $attributes The block attributes. 14 * @param string $content The block content. 16 15 * 17 16 * @return string Returns the block content. 18 17 */ 19 18 function render_block_core_file( $attributes, $content ) { 20 // If it's interactive, enqueue the script module and add the directives. 21 if ( ! empty( $attributes['displayPreview'] ) ) { 22 wp_enqueue_script_module( '@wordpress/block-library/file/view' ); 23 24 $processor = new WP_HTML_Tag_Processor( $content ); 25 $processor->next_tag(); 26 $processor->set_attribute( 'data-wp-interactive', 'core/file' ); 27 $processor->next_tag( 'object' ); 28 $processor->set_attribute( 'data-wp-bind--hidden', '!state.hasPdfPreview' ); 29 $processor->set_attribute( 'hidden', true ); 30 31 $filename = $processor->get_attribute( 'aria-label' ); 32 $has_filename = ! empty( $filename ) && 'PDF embed' !== $filename; 33 $label = $has_filename ? sprintf( 34 /* translators: %s: filename. */ 35 __( 'Embed of %s.' ), 36 $filename 37 ) : __( 'PDF embed' ); 38 39 // Update object's aria-label attribute if present in block HTML. 40 // Match an aria-label attribute from an object tag. 41 $processor->set_attribute( 'aria-label', $label ); 42 43 return $processor->get_updated_html(); 19 if ( empty( $attributes['displayPreview'] ) ) { 20 return $content; 44 21 } 45 22 46 return $content; 23 // If it's interactive, enqueue the script module and add the directives. 24 wp_enqueue_script_module( '@wordpress/block-library/file/view' ); 25 26 $processor = new WP_HTML_Tag_Processor( $content ); 27 if ( $processor->next_tag() ) { 28 $processor->set_attribute( 'data-wp-interactive', 'core/file' ); 29 } 30 31 // If there are no OBJECT elements, something might have already modified the block. 32 if ( ! $processor->next_tag( 'OBJECT' ) ) { 33 return $content; 34 } 35 36 $processor->set_attribute( 'data-wp-bind--hidden', '!state.hasPdfPreview' ); 37 $processor->set_attribute( 'hidden', true ); 38 39 $filename = $processor->get_attribute( 'aria-label' ); 40 $has_filename = is_string( $filename ) && ! empty( $filename ) && 'PDF embed' !== $filename; 41 $label = $has_filename ? sprintf( 42 /* translators: %s: filename. */ 43 __( 'Embed of %s.' ), 44 $filename 45 ) : __( 'PDF embed' ); 46 47 // Update object's aria-label attribute if present in block HTML. 48 // Match an aria-label attribute from an object tag. 49 $processor->set_attribute( 'aria-label', $label ); 50 51 return $processor->get_updated_html(); 47 52 } 48 53
Note: See TracChangeset
for help on using the changeset viewer.