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

Add experimental flag and enable widgets screen in customizer #28618

Merged
Merged
Show file tree
Hide file tree
Changes from 11 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
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,12 @@
"markdown_source": "../packages/custom-templated-path-webpack-plugin/README.md",
"parent": "packages"
},
{
"title": "@wordpress/customize-widgets",
"slug": "packages-customize-widgets",
"markdown_source": "../packages/customize-widgets/README.md",
"parent": "packages"
},
{
"title": "@wordpress/data-controls",
"slug": "packages-data-controls",
Expand Down
42 changes: 42 additions & 0 deletions lib/class-wp-sidebar-block-editor-control.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Widget API: WP_Sidebar_Block_Editor_Control class.
*
* @package Gutenberg
*/

/**
* Core class used to implement the widgets block editor control in the customizer.
*
* @see WP_Customize_Control
*/
class WP_Sidebar_Block_Editor_Control extends WP_Customize_Control {
/**
* The control type.
*
* @var string
*/
public $type = 'sidebar_block_editor';

/**
* The current sidebar ID.
*
* @var string
*/
public $sidebar_id;
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Enqueue the scripts and styles.
*/
public function enqueue() {
wp_enqueue_script( 'wp-customize-widgets' );
wp_enqueue_style( 'wp-customize-widgets' );
}

/**
* Render the widgets block editor container.
*/
public function render_content() {
// Render nothing.
}
}
1 change: 0 additions & 1 deletion lib/class-wp-widget-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,4 @@ public function set_is_wide_widget_in_customizer( $is_wide, $widget_id ) {

return $is_wide;
}

}
9 changes: 9 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,15 @@ function gutenberg_register_packages_styles( $styles ) {
filemtime( gutenberg_dir_path() . 'build/block-directory/style.css' )
);
$styles->add_data( 'wp-block-directory', 'rtl', 'replace' );

gutenberg_override_style(
$styles,
'wp-customize-widgets',
gutenberg_url( 'build/customize-widgets/style.css' ),
array( 'wp-components', 'wp-block-editor', 'wp-edit-blocks' ),
filemtime( gutenberg_dir_path() . 'build/customize-widgets/style.css' )
);
$styles->add_data( 'wp-customize-widgets', 'rtl', 'replace' );
}
add_action( 'wp_default_styles', 'gutenberg_register_packages_styles' );

Expand Down
11 changes: 11 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-navigation',
)
);
add_settings_field(
'gutenberg-widgets-in-customizer',
__( 'Widgets', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Enable Widgets screen in Customizer', 'gutenberg' ),
'id' => 'gutenberg-widgets-in-customizer',
)
);
register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/client-assets.php';
require __DIR__ . '/demo.php';
require __DIR__ . '/widgets.php';
require __DIR__ . '/widgets-customize.php';
require __DIR__ . '/navigation.php';
require __DIR__ . '/navigation-page.php';
require __DIR__ . '/experiments-page.php';
Expand Down
64 changes: 64 additions & 0 deletions lib/widgets-customize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Bootstrapping the Gutenberg widgets editor in the customizer.
*
* @package gutenberg
*/

/**
* Gutenberg's Customize Register.
*
* Adds a section to the Customizer for editing widgets with Gutenberg.
*
* @param \WP_Customize_Manager $manager An instance of the class that controls most of the Theme Customization API for WordPress 3.4 and newer.
*/
function gutenberg_widgets_customize_register( $manager ) {
global $wp_registered_sidebars;

if ( ! gutenberg_use_widgets_block_editor() ) {
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

require_once __DIR__ . '/class-wp-sidebar-block-editor-control.php';

foreach ( $manager->sections() as $section ) {
if ( $section instanceof WP_Customize_Sidebar_Section ) {
$section->description = '';
}
}
foreach ( $manager->controls() as $control ) {
if (
$control instanceof WP_Widget_Area_Customize_Control ||
$control instanceof WP_Widget_Form_Customize_Control
) {
$manager->remove_control( $control->id );
}
}

foreach ( $wp_registered_sidebars as $sidebar_id => $sidebar ) {
$manager->add_setting(
noisysocks marked this conversation as resolved.
Show resolved Hide resolved
"sidebars_widgets[$sidebar_id]",
array(
'type' => 'gutenberg_widget_blocks',
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved
'capability' => 'edit_theme_options',
'transport' => 'postMessage',
)
);

$manager->add_control(
new WP_Sidebar_Block_Editor_Control(
$manager,
"sidebars_widgets[$sidebar_id]",
array(
'section' => "sidebar-widgets-$sidebar_id",
'settings' => "sidebars_widgets[$sidebar_id]",
'sidebar_id' => $sidebar_id,
)
)
);
}
}

if ( gutenberg_is_experiment_enabled( 'gutenberg-widgets-in-customizer' ) ) {
add_action( 'customize_register', 'gutenberg_widgets_customize_register' );
}
2 changes: 1 addition & 1 deletion lib/widgets-page.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Bootstraping the Gutenberg widgets page.
* Bootstrapping the Gutenberg widgets page.
*
* @package gutenberg
*/
Expand Down
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@wordpress/components": "file:packages/components",
"@wordpress/compose": "file:packages/compose",
"@wordpress/core-data": "file:packages/core-data",
"@wordpress/customize-widgets": "file:packages/customize-widgets",
"@wordpress/data": "file:packages/data",
"@wordpress/data-controls": "file:packages/data-controls",
"@wordpress/date": "file:packages/date",
Expand Down
1 change: 1 addition & 0 deletions packages/customize-widgets/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
5 changes: 5 additions & 0 deletions packages/customize-widgets/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/master/packages#maintaining-changelogs. -->

## Unreleased

Initial release.
6 changes: 6 additions & 0 deletions packages/customize-widgets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- Package name
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved
- Package description
- Installation details
- Usage example
- API documentation, if applicable ([more info](#maintaining-api-documentation))
- `Code is Poetry` logo (`<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>`)
32 changes: 32 additions & 0 deletions packages/customize-widgets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@wordpress/customize-widgets",
"version": "1.0.0-prerelease",
"description": "Package description.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's write a very brief description here.

"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
"keywords": [ "wordpress" ],
"homepage": "https://github.com/WordPress/gutenberg/tree/master/packages/customize-widgets/README.md",
"repository": {
"type": "git",
"url": "https://github.com/WordPress/gutenberg.git",
"directory": "packages/customize-widgets"
},
"bugs": {
"url": "https://github.com/WordPress/gutenberg/issues"
},
"main": "build/index.js",
"module": "build-module/index.js",
"react-native": "src/index",
"dependencies": {
"@babel/runtime": "^7.11.2",
"@wordpress/block-editor": "file:../block-editor",
"@wordpress/block-library": "file:../block-library",
"@wordpress/blocks": "file:../blocks",
"@wordpress/components": "file:../components",
"@wordpress/element": "file:../element",
"lodash": "^4.17.19"
},
"publishConfig": {
"access": "public"
}
}
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* WordPress dependencies
*/
import {
BlockEditorProvider,
BlockList,
BlockSelectionClearer,
ObserveTyping,
WritingFlow,
} from '@wordpress/block-editor';
import {
DropZoneProvider,
FocusReturnProvider,
SlotFillProvider,
} from '@wordpress/components';

/**
* Internal dependencies
*/
import useSidebarBlockEditor from './use-sidebar-block-editor';

export default function CustomizeSidebarBlockEditor( { sidebar } ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The file name is sidebar-block-editor but the component name is CustomizeSidebarBlockEditor. Might be nice to make em consistent.

const [ blocks, onInput, onChange ] = useSidebarBlockEditor( sidebar );

return (
<SlotFillProvider>
<DropZoneProvider>
<FocusReturnProvider>
<BlockEditorProvider
value={ blocks }
onInput={ onInput }
onChange={ onChange }
>
<BlockSelectionClearer>
<WritingFlow>
<ObserveTyping>
<BlockList />
</ObserveTyping>
</WritingFlow>
</BlockSelectionClearer>
</BlockEditorProvider>
</FocusReturnProvider>
</DropZoneProvider>
</SlotFillProvider>
);
}
Loading