Skip to content

Commit

Permalink
Pass block attributes with rendering with location (#33043)
Browse files Browse the repository at this point in the history
* Pass block attributes with rendering with location

When the Navigation block is rendering via the __unstableLocation
attribute the attributes are now passed to the rendering function. The
rendering function was already expecting 'block_attribute' this change
just passes it along.

* Added parameter to comment documentation.

* formatting fix

Co-authored-by: Ben Dwyer <[email protected]>
  • Loading branch information
pbking and scruffian authored Jun 30, 2021
1 parent e0fd696 commit d3fb83c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,22 @@ function block_core_navigation_build_css_font_sizes( $attributes ) {
* If no location was provided as a block attribute then false is returned.
*
* @param string $location The location of the classic menu to display.
* @param object $attributes The block attributes.
* @return string|false HTML markup of a generated Navigation Block or false if no location is specified.
*/
function gutenberg_render_menu_from_location( $location ) {
function gutenberg_render_menu_from_location( $location, $attributes ) {
if ( empty( $location ) ) {
return false;
}

return wp_nav_menu(
array(
'theme_location' => $location,
'container' => '',
'items_wrap' => '%3$s',
'fallback_cb' => false,
'echo' => false,
'theme_location' => $location,
'container' => '',
'items_wrap' => '%3$s',
'block_attributes' => $attributes,
'fallback_cb' => false,
'echo' => false,
)
);
}
Expand Down Expand Up @@ -154,7 +156,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
if ( empty( $block->inner_blocks ) ) {
if ( array_key_exists( '__unstableLocation', $attributes ) ) {
$location = $attributes['__unstableLocation'];
$maybe_classic_navigation = gutenberg_render_menu_from_location( $location );
$maybe_classic_navigation = gutenberg_render_menu_from_location( $location, $attributes );
if ( $maybe_classic_navigation ) {
return $maybe_classic_navigation;
}
Expand Down

0 comments on commit d3fb83c

Please sign in to comment.