Skip to content

Commit

Permalink
Dynamically opt-in to interactivity support in File and Navigation bl…
Browse files Browse the repository at this point in the history
…ocks

Co-authored-by: Luis Herranz <[email protected]>
  • Loading branch information
westonruter and luisherranz committed Jul 12, 2023
1 parent abb8410 commit d33578c
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Add a link to a downloadable file. ([Source](https://github.com/WordPress/gutenb

- **Name:** core/file
- **Category:** media
- **Supports:** align, anchor, color (background, gradients, link, ~~text~~), interactivity
- **Supports:** align, anchor, color (background, gradients, link, ~~text~~)
- **Attributes:** displayPreview, downloadButtonText, fileId, fileName, href, id, previewHeight, showDownloadButton, textLinkHref, textLinkTarget

## Footnotes
Expand Down Expand Up @@ -421,7 +421,7 @@ A collection of blocks that allow visitors to get around your site. ([Source](ht

- **Name:** core/navigation
- **Category:** theme
- **Supports:** align (full, wide), inserter, interactivity, layout (allowSizingOnChildren, default, ~~allowInheriting~~, ~~allowSwitching~~, ~~allowVerticalAlignment~~), spacing (blockGap, units), typography (fontSize, lineHeight), ~~html~~
- **Supports:** align (full, wide), inserter, layout (allowSizingOnChildren, default, ~~allowInheriting~~, ~~allowSwitching~~, ~~allowVerticalAlignment~~), spacing (blockGap, units), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** __unstableLocation, backgroundColor, customBackgroundColor, customOverlayBackgroundColor, customOverlayTextColor, customTextColor, hasIcon, icon, maxNestingLevel, openSubmenusOnClick, overlayBackgroundColor, overlayMenu, overlayTextColor, ref, rgbBackgroundColor, rgbTextColor, showSubmenuIcon, templateLock, textColor

## Custom Link
Expand Down
2 changes: 1 addition & 1 deletion lib/experimental/interactivity-api/scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function gutenberg_interactivity_move_interactive_scripts_to_the_footer() {
// Move all the view scripts of the interactive blocks to the footer.
$registered_blocks = \WP_Block_Type_Registry::get_instance()->get_all_registered();
foreach ( array_values( $registered_blocks ) as $block ) {
if ( isset( $block->supports['interactivity'] ) && $block->supports['interactivity'] && gutenberg_should_block_use_interactivity_api( $block->name ) ) {
if ( isset( $block->supports['interactivity'] ) && $block->supports['interactivity'] ) {
foreach ( $block->view_script_handles as $handle ) {
wp_script_add_data( $handle, 'group', 1 );
}
Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/src/file/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@
"background": true,
"link": true
}
},
"interactivity": true
}
},
"viewScript": "file:./view.min.js",
"editorStyle": "wp-block-file-editor",
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/file/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/
function gutenberg_block_core_file_update_interactive_view_script( $metadata ) {
if ( 'core/file' === $metadata['name'] ) {
$metadata['viewScript'] = array( 'file:./view-interactivity.min.js' );
$metadata['viewScript'] = array( 'file:./view-interactivity.min.js' );
$metadata['supports']['interactivity'] = true;
}
return $metadata;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/src/navigation/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@
}
}
}
},
"interactivity": true
}
},
"viewScript": [ "file:./view.min.js", "file:./view-modal.min.js" ],
"editorStyle": "wp-block-navigation-editor",
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ function block_core_navigation_add_directives_to_submenu( $w, $block_attributes
*/
function gutenberg_block_core_navigation_update_interactive_view_script( $metadata ) {
if ( 'core/navigation' === $metadata['name'] ) {
$metadata['viewScript'] = array( 'file:./view-interactivity.min.js' );
$metadata['viewScript'] = array( 'file:./view-interactivity.min.js' );
$metadata['supports']['interactivity'] = true;
}
return $metadata;
}
Expand Down

0 comments on commit d33578c

Please sign in to comment.