From 4e133c3d3909a67c820d52cfeb0684e2e2d0a3ec Mon Sep 17 00:00:00 2001 From: Maggie Date: Fri, 27 Aug 2021 12:48:08 +0200 Subject: [PATCH] Blockbase + co: Universal Social menu (#4467) * used render_callback to insert social menu from customizer * return block content early * change the condition under which we hijack the menu * Remove extra navigation * output block markup for the whole menu * Render the menu at the social location, rather than the one called social * map the right alignment from the nav block to the social icons block * move the social nav to skatepark * Replace any trailing numbers on menu items to better match them to service names Co-authored-by: Ben Dwyer --- blockbase/functions.php | 54 ++++++++++++++++++++++ skatepark/block-template-parts/header.html | 9 ++-- skatepark/functions.php | 3 +- 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/blockbase/functions.php b/blockbase/functions.php index faa0ecf622..c44383984c 100644 --- a/blockbase/functions.php +++ b/blockbase/functions.php @@ -119,3 +119,57 @@ function blockbase_restore_customizer() { require get_template_directory() . '/inc/customizer/wp-customize-colors.php'; require get_template_directory() . '/inc/customizer/wp-customize-color-palettes.php'; require get_template_directory() . '/inc/customizer/wp-customize-fonts.php'; + +/** + * Populate the social links block with the social menu content if it exists + * + */ +add_filter( 'render_block', 'blockbase_social_menu_render', 10, 2 ); +// We should only change the render of the navigtion block +// to social links in the following conditions. +function blockbase_condition_to_render_social_menu( $block ) { + // The block should be a navigation block. + if ( 'core/navigation' !== $block['blockName'] ) { + return false; + } + + // The theme should have a menu defined at the social location. + if ( ! has_nav_menu( 'social' ) ) { + return false; + } + + // The block should have a loction defined. + if ( empty( $block['attrs']['__unstableLocation'] ) ) { + return false; + } + + // The block's location should be 'social'. + if ( $block['attrs']['__unstableLocation'] !== 'social' ) { + return false; + } + + return true; +} + +function blockbase_social_menu_render( $block_content, $block ) { + if ( blockbase_condition_to_render_social_menu( $block ) ) { + $nav_menu_locations = get_nav_menu_locations(); + $social_menu_id = $nav_menu_locations['social']; + $class_name = 'is-style-logos-only'; + if( !empty( $block['attrs']['itemsJustification'] ) && $block['attrs']['itemsJustification'] === 'right' ) { + $class_name .= ' items-justified-right'; + } + $block_content = ''; + + return do_blocks( $block_content ); + } + + return $block_content; +} diff --git a/skatepark/block-template-parts/header.html b/skatepark/block-template-parts/header.html index 529e797349..cd6e1c8474 100644 --- a/skatepark/block-template-parts/header.html +++ b/skatepark/block-template-parts/header.html @@ -11,13 +11,10 @@ + - \ No newline at end of file + diff --git a/skatepark/functions.php b/skatepark/functions.php index c77b025a8b..b741b00478 100644 --- a/skatepark/functions.php +++ b/skatepark/functions.php @@ -24,7 +24,8 @@ function skatepark_support() { //Primary navigation is used on the header and the footer pattern register_nav_menus( array( - 'primary' => __( 'Primary Navigation', 'skatepark' ) + 'primary' => __( 'Primary Navigation', 'skatepark' ), + 'social' => __( 'Social Navigation', 'blockbase' ) ) );