Skip to content

Commit b106720

Browse files
committed
Move directives inside gutenberg_process_interactive_html
1 parent 22f6131 commit b106720

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

lib/experimental/interactivity-api/directive-processing.php

+21-26
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ function gutenberg_interactivity_mark_root_blocks( $parsed_block, $source_block,
3636
* @return string Filtered block content.
3737
*/
3838
function gutenberg_process_directives_in_root_blocks( $block_content, $block ) {
39-
static $directives = array(
40-
'data-wp-context' => 'gutenberg_interactivity_process_wp_context',
41-
'data-wp-bind' => 'gutenberg_interactivity_process_wp_bind',
42-
'data-wp-class' => 'gutenberg_interactivity_process_wp_class',
43-
'data-wp-style' => 'gutenberg_interactivity_process_wp_style',
44-
'data-wp-text' => 'gutenberg_interactivity_process_wp_text',
45-
);
46-
4739
if ( WP_Directive_Processor::is_marked_as_root_block( $block ) ) {
4840
WP_Directive_Processor::unmark_root_block();
4941

@@ -54,9 +46,9 @@ function gutenberg_process_directives_in_root_blocks( $block_content, $block ) {
5446

5547
foreach ( $parsed_blocks as $parsed_block ) {
5648
if ( 'core/interactivity-wrapper' === $parsed_block['blockName'] ) {
57-
$processed_content .= gutenberg_process_interactive_block( $parsed_block, $context, $directives );
49+
$processed_content .= gutenberg_process_interactive_block( $parsed_block, $context );
5850
} elseif ( 'core/non-interactivity-wrapper' === $parsed_block['blockName'] ) {
59-
$processed_content .= gutenberg_process_non_interactive_block( $parsed_block, $context, $directives );
51+
$processed_content .= gutenberg_process_non_interactive_block( $parsed_block, $context );
6052
} else {
6153
$processed_content .= $parsed_block['innerHTML'];
6254
}
@@ -126,11 +118,10 @@ function gutenberg_mark_block_interactivity( $block_content, $block, $block_inst
126118
*
127119
* @param array $interactive_block The interactive block to process.
128120
* @param WP_Directive_Context $context The context to use when processing.
129-
* @param array $directives The directives to apply.
130121
*
131122
* @return string The processed HTML.
132123
*/
133-
function gutenberg_process_interactive_block( $interactive_block, $context, $directives ) {
124+
function gutenberg_process_interactive_block( $interactive_block, $context ) {
134125
$block_index = 0;
135126
$content = '';
136127
$interactive_inner_blocks = array();
@@ -146,7 +137,7 @@ function gutenberg_process_interactive_block( $interactive_block, $context, $dir
146137
}
147138
}
148139

149-
return gutenberg_process_interactive_html( $content, $context, $directives, $interactive_inner_blocks );
140+
return gutenberg_process_interactive_html( $content, $context, $interactive_inner_blocks );
150141
}
151142

152143
/**
@@ -156,11 +147,10 @@ function gutenberg_process_interactive_block( $interactive_block, $context, $dir
156147
*
157148
* @param array $non_interactive_block The non-interactive block to process.
158149
* @param WP_Directive_Context $context The context to use when processing.
159-
* @param array $directives The directives to apply.
160150
*
161151
* @return string The processed HTML.
162152
*/
163-
function gutenberg_process_non_interactive_block( $non_interactive_block, $context, $directives ) {
153+
function gutenberg_process_non_interactive_block( $non_interactive_block, $context ) {
164154
$block_index = 0;
165155
$content = '';
166156
foreach ( $non_interactive_block['innerContent'] as $inner_content ) {
@@ -174,9 +164,9 @@ function gutenberg_process_non_interactive_block( $non_interactive_block, $conte
174164
$inner_block = $non_interactive_block['innerBlocks'][ $block_index++ ];
175165

176166
if ( 'core/interactivity-wrapper' === $inner_block['blockName'] ) {
177-
$content .= gutenberg_process_interactive_block( $inner_block, $context, $directives );
167+
$content .= gutenberg_process_interactive_block( $inner_block, $context );
178168
} elseif ( 'core/non-interactivity-wrapper' === $inner_block['blockName'] ) {
179-
$content .= gutenberg_process_non_interactive_block( $inner_block, $context, $directives );
169+
$content .= gutenberg_process_non_interactive_block( $inner_block, $context );
180170
}
181171
}
182172
}
@@ -187,20 +177,25 @@ function gutenberg_process_non_interactive_block( $non_interactive_block, $conte
187177
* Processes interactive HTML by applying directives to the HTML tags.
188178
*
189179
* It uses the WP_Directive_Processor class to parse the HTML and apply the
190-
* directives. The directives are specified in the $directives array and are
191-
* applied to the tags that have the corresponding data attribute. If a tag
192-
* contains a 'WP-INNER-BLOCKS' string and there are inner blocks to process,
193-
* the function processes these inner blocks and replaces the 'WP-INNER-BLOCKS'
194-
* tag in the HTML with those blocks.
180+
* directives. If a tag contains a 'WP-INNER-BLOCKS' string and there are inner
181+
* blocks to process, the function processes these inner blocks and replaces the
182+
* 'WP-INNER-BLOCKS' tag in the HTML with those blocks.
195183
*
196184
* @param string $html The HTML to process.
197185
* @param mixed $context The context to use when processing.
198-
* @param array $directives The directives to apply.
199186
* @param array $inner_blocks The inner blocks to process.
200187
*
201188
* @return string The processed HTML.
202189
*/
203-
function gutenberg_process_interactive_html( $html, $context, $directives, $inner_blocks = array() ) {
190+
function gutenberg_process_interactive_html( $html, $context, $inner_blocks = array() ) {
191+
static $directives = array(
192+
'data-wp-context' => 'gutenberg_interactivity_process_wp_context',
193+
'data-wp-bind' => 'gutenberg_interactivity_process_wp_bind',
194+
'data-wp-class' => 'gutenberg_interactivity_process_wp_class',
195+
'data-wp-style' => 'gutenberg_interactivity_process_wp_style',
196+
'data-wp-text' => 'gutenberg_interactivity_process_wp_text',
197+
);
198+
204199
$tags = new WP_Directive_Processor( $html );
205200
$prefix = 'data-wp-';
206201
$tag_stack = array();
@@ -212,9 +207,9 @@ function gutenberg_process_interactive_html( $html, $context, $directives, $inne
212207
// Processes the inner blocks.
213208
if ( str_contains( $tag_name, 'WP-INNER-BLOCKS' ) && ! empty( $inner_blocks ) && ! $tags->is_tag_closer() ) {
214209
if ( 'core/interactivity-wrapper' === $inner_blocks[ $inner_blocks_index ]['blockName'] ) {
215-
$inner_processed_blocks[ strtolower( $tag_name ) ] = gutenberg_process_interactive_block( $inner_blocks[ $inner_blocks_index++ ], $context, $directives );
210+
$inner_processed_blocks[ strtolower( $tag_name ) ] = gutenberg_process_interactive_block( $inner_blocks[ $inner_blocks_index++ ], $context );
216211
} elseif ( 'core/non-interactivity-wrapper' === $inner_blocks[ $inner_blocks_index ]['blockName'] ) {
217-
$inner_processed_blocks[ strtolower( $tag_name ) ] = gutenberg_process_non_interactive_block( $inner_blocks[ $inner_blocks_index++ ], $context, $directives );
212+
$inner_processed_blocks[ strtolower( $tag_name ) ] = gutenberg_process_non_interactive_block( $inner_blocks[ $inner_blocks_index++ ], $context );
218213
}
219214
}
220215
if ( $tags->is_tag_closer() ) {

0 commit comments

Comments
 (0)