Skip to content

Commit

Permalink
encapsulate experiment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieCabrera committed Feb 2, 2024
1 parent 67e700f commit b3783d0
Showing 1 changed file with 66 additions and 32 deletions.
98 changes: 66 additions & 32 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ private static function is_always_overlay( $attributes ) {
* @return bool Returns whether or not the navigation is collapsable.
*/
private static function is_collapsable( $attributes ) {

$gutenberg_experiments = get_option( 'gutenberg-experiments' );
if ( empty( $gutenberg_experiments ) || ! array_key_exists( 'gutenberg-navigation-overlay-auto', $gutenberg_experiments ) ) {
return;
}

return isset( $attributes['overlayMenu'] ) && in_array( $attributes['overlayMenu'], array( 'mobile', 'auto' ), true );
}

Expand Down Expand Up @@ -550,40 +556,68 @@ private static function get_nav_element_directives( $is_interactive, $attributes
$gutenberg_experiments = get_option( 'gutenberg-experiments' );
$is_experiment = ( $gutenberg_experiments && array_key_exists( 'gutenberg-navigation-overlay-auto', $gutenberg_experiments ) ) ? true : false;

$overlay_menu = $is_experiment ? 'auto' : $attributes['overlayMenu'];
if( $is_experiment ) {

Check failure on line 559 in packages/block-library/src/navigation/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Space after opening control structure is required

Check failure on line 559 in packages/block-library/src/navigation/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

No space before opening parenthesis is prohibited

Check failure on line 559 in packages/block-library/src/navigation/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 space after IF keyword; 0 found
$overlay_menu = $is_experiment ? 'auto' : $attributes['overlayMenu'];

// When adding to this array be mindful of security concerns.
$nav_element_context = wp_json_encode(
array(
'overlayOpenedBy' => array(),
'type' => 'overlay',
'roleAttribute' => '',
'ariaLabel' => __( 'Menu' ),
'overlayMenu' => $overlay_menu,
),
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP
);
$nav_element_directives = '
data-wp-interactive=\'{"namespace":"core/navigation"}\'
data-wp-context=\'' . $nav_element_context . '\'
';

/*
* When the navigation's 'overlayMenu' attribute is set to 'always', JavaScript
* is not needed for collapsing the menu because the class is set manually.
*/
if ( static::is_collapsable( $attributes ) ) {
$nav_element_directives .= ' '; // space separator
$nav_element_directives .= 'data-wp-class--is-collapsed="context.isCollapsed"';
}
// When adding to this array be mindful of security concerns.
$nav_element_context = wp_json_encode(

Check warning on line 563 in packages/block-library/src/navigation/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned correctly; expected 1 space but found 4 spaces
array(
'overlayOpenedBy' => array(),
'type' => 'overlay',
'roleAttribute' => '',
'ariaLabel' => __( 'Menu' ),
'overlayMenu' => $overlay_menu,
),
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP
);

if ( isset( $overlay_menu ) && 'mobile' === $overlay_menu ) {
$nav_element_directives .= ' '; // space separator
$nav_element_directives .= 'data-wp-init="callbacks.initMobileNav"';
}
if ( isset( $overlay_menu ) && 'auto' === $overlay_menu ) {
$nav_element_directives .= ' '; // space separator
$nav_element_directives .= 'data-wp-init="callbacks.initAutoNav"';
$nav_element_directives = '
data-wp-interactive=\'{"namespace":"core/navigation"}\'
data-wp-context=\'' . $nav_element_context . '\'
';

/*
* When the navigation's 'overlayMenu' attribute is set to 'always', JavaScript
* is not needed for collapsing the menu because the class is set manually.
*/
if ( static::is_collapsable( $attributes ) ) {
$nav_element_directives .= ' '; // space separator
$nav_element_directives .= 'data-wp-class--is-collapsed="context.isCollapsed"';
}

if ( isset( $overlay_menu ) && 'mobile' === $overlay_menu ) {
$nav_element_directives .= ' '; // space separator
$nav_element_directives .= 'data-wp-init="callbacks.initMobileNav"';
}
if ( isset( $overlay_menu ) && 'auto' === $overlay_menu ) {
$nav_element_directives .= ' '; // space separator
$nav_element_directives .= 'data-wp-init="callbacks.initAutoNav"';
}
} else {
// When adding to this array be mindful of security concerns.
$nav_element_context = wp_json_encode(

Check warning on line 598 in packages/block-library/src/navigation/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Equals sign not aligned correctly; expected 1 space but found 4 spaces
array(
'overlayOpenedBy' => array(),
'type' => 'overlay',
'roleAttribute' => '',
'ariaLabel' => __( 'Menu' ),
),
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP
);

$nav_element_directives = '
data-wp-interactive=\'{"namespace":"core/navigation"}\'
data-wp-context=\'' . $nav_element_context . '\'
';

/*
* When the navigation's 'overlayMenu' attribute is set to 'always', JavaScript
* is not needed for collapsing the menu because the class is set manually.
*/
if ( ! static::is_always_overlay( $attributes ) ) {
$nav_element_directives .= ' '; // space separator
$nav_element_directives .= 'data-wp-class--is-collapsed="context.isCollapsed"';
}
}

return $nav_element_directives;
Expand Down

0 comments on commit b3783d0

Please sign in to comment.