From 43bc49db969e7e15b213e3a7cc4452514fc899a5 Mon Sep 17 00:00:00 2001 From: Artemio Morales Date: Thu, 1 Jun 2023 15:46:31 +0200 Subject: [PATCH] Experiment: Put directives on
element and insert lightbox as its child (#51089) * Put directives on
element and insert lightbox as its child * Fix PHP spacing * Ensure
directives are only rendered in body content The
directives were rendering not only in the body content, but also the lightbox. This ensures the directives do not appear in the lightbox. * Improve syntax * Change directives suffix and `data-wp-island` --------- Co-authored-by: Mario Santos --- packages/block-library/src/image/index.php | 58 +++++++++++----------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/packages/block-library/src/image/index.php b/packages/block-library/src/image/index.php index 53cc873cee05a..3c90f0fbc21cf 100644 --- a/packages/block-library/src/image/index.php +++ b/packages/block-library/src/image/index.php @@ -59,6 +59,13 @@ function render_block_core_image( $attributes, $content ) { } $content = $processor->get_updated_html(); + $w = new WP_HTML_Tag_Processor( $content ); + $w->next_tag( 'figure' ); + $w->add_class( 'wp-lightbox-container' ); + $w->set_attribute( 'data-wp-interactive', true ); + $w->set_attribute( 'data-wp-context', '{ "core": { "image": { "initialized": false, "lightboxEnabled": false } } }' ); + $body_content = $w->get_updated_html(); + // Wrap the image in the body content with a button. $img = null; preg_match( '/]+>/', $content, $img ); @@ -66,41 +73,36 @@ function render_block_core_image( $attributes, $content ) { ' . $img[0] . ''; - $body_content = preg_replace( '/]+>/', $button, $content ); + $body_content = preg_replace( '/]+>/', $button, $body_content ); $background_color = esc_attr( wp_get_global_styles( array( 'color', 'background' ) ) ); $close_button_icon = ''; - $dialog_label = $alt_attribute ? esc_attr( $alt_attribute ) : esc_attr__( 'Image' ); - + $dialog_label = $alt_attribute ? esc_attr( $alt_attribute ) : esc_attr__( 'Image' ); $close_button_label = esc_attr__( 'Close' ); - return - << - $body_content - - + $lightbox_html = << + + $content +
+ HTML; + + return str_replace( '
', $lightbox_html . '
', $body_content ); } return $processor->get_updated_html();