Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change search block's default settings #44

Merged
merged 2 commits into from
May 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions includes/class-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct() {
\add_action( 'after_setup_theme', [ __CLASS__, 'theme_support' ] );
\add_action( 'wp_enqueue_scripts', [ __CLASS__, 'theme_styles' ] );
\add_action( 'enqueue_block_editor_assets', [ __CLASS__, 'editor_scripts' ] );
\add_filter( 'block_type_metadata', [ __CLASS__, 'block_variations' ] );
}

/**
Expand Down Expand Up @@ -86,6 +87,26 @@ public static function editor_scripts() {
// Enqueue editor JavaScript.
wp_enqueue_script( 'editor-script', get_theme_file_uri( '/dist/editor.js' ), array( 'wp-blocks', 'wp-dom' ), wp_get_theme()->get( 'Version' ), true );
}

/**
* Add block variations.
*
* @since Newspack Block Theme 1.0
*
* We may be able to replace this with JavaScript; I'm unclear whether isDefault isn't working, or just not working as I expect it to.
* See: https://github.com/WordPress/gutenberg/issues/28119
*
* @return array Block metadata.
*/
public static function block_variations( $metadata ) {
if ( $metadata[ 'name' ] == 'core/search' ) {
$metadata['attributes']['buttonPosition']['default'] = 'button-inside';
$metadata['attributes']['buttonUseIcon']['default'] = true;
$metadata['attributes']['placeholder']['default'] = esc_html__( 'Search...', 'newspack-block-theme' );
$metadata['attributes']['showLabel']['default'] = false;
}
return $metadata;
}
}

Core::instance();