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

Image block: UI updates for the image lightbox (redo) #54509

Merged
merged 93 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
08bb1ed
Begin removing theme.json dependency in block UI
artemiomorales Aug 21, 2023
c93f1b6
Remove the useHasBehaviorsPanel hook
michalczaplinski Aug 21, 2023
25aa1c6
Fix declaration to actually retrieve from user data
artemiomorales Aug 21, 2023
a8c09c9
Restructured use of global behaviors
michalczaplinski Aug 21, 2023
fac2e3a
More removal of behaviors.
michalczaplinski Aug 28, 2023
dfc1c46
Remove the reference to behaviors in Global styles and first iteratio…
michalczaplinski Aug 28, 2023
51e4802
Remove behaviors altogether and everywhere
michalczaplinski Aug 29, 2023
b416558
Fix linter & sniffer PHP errors
michalczaplinski Aug 30, 2023
321a213
Adjust schema properties count assertion
michalczaplinski Aug 30, 2023
e613a5b
Add initial implementation of image settings panel
artemiomorales Aug 30, 2023
0021116
Add the lightbox attribute
michalczaplinski Aug 30, 2023
6951a86
Remove unnecessary space
michalczaplinski Aug 30, 2023
b0fb3b5
Remove unnecessary code and fix reset functionality
artemiomorales Aug 30, 2023
b76d56c
Add UI to image block inspector
artemiomorales Aug 30, 2023
1872f77
Add `lightbox` to the valid `theme.json` settings
michalczaplinski Aug 31, 2023
3cfcb15
Merge branch 'update/revise-lightbox-ui' into update/lightbox-setting…
michalczaplinski Aug 31, 2023
d2818af
Fix a bug with image selector and integrate with global styles
michalczaplinski Aug 31, 2023
a32d0f6
Update `theme.json` schema
michalczaplinski Sep 2, 2023
e67634e
Added the `@since`annotation
michalczaplinski Sep 2, 2023
3ddb1b1
Refactor image settings panel and screen block
michalczaplinski Sep 4, 2023
fae6f99
Add showUI option to lightbox settings
michalczaplinski Sep 4, 2023
df9f857
Add defaults for the `lightbox` to the GB `theme.json`
michalczaplinski Sep 4, 2023
df3f1c6
Change the falsy checks in image.js
michalczaplinski Sep 4, 2023
075535b
Add filters; add legacy support for behaviors syntax
artemiomorales Sep 5, 2023
c2a0b3f
Fix linter errors & add more expansive comments.
michalczaplinski Sep 5, 2023
91d130c
If no value is set for the lightbox in the Global Styles, then the bl…
michalczaplinski Sep 5, 2023
c58612c
Rename `showUI` to `allowEditing`
michalczaplinski Sep 5, 2023
c602139
Fix the `theme.json` schema
michalczaplinski Sep 5, 2023
339a715
Use the globalPath for the settings on the PHP side
michalczaplinski Sep 5, 2023
4b43b30
Add backwards support for enabling fade animation via the legacy syntax
artemiomorales Sep 6, 2023
ce3c338
Fix PHP linter errors
artemiomorales Sep 6, 2023
92b084f
Merge branch 'trunk' into update/revise-lightbox-ui
michalczaplinski Sep 6, 2023
7fefb83
Merge branch 'update/revise-lightbox-ui' into update/lightbox-setting…
michalczaplinski Sep 6, 2023
03e60d7
Fix error when checking lightbox['enabled'] value in global settings
artemiomorales Sep 6, 2023
050c636
Empty commit
michalczaplinski Sep 6, 2023
521d950
Remove the default `false` value for `lightbox.enabled`attribute.
michalczaplinski Sep 7, 2023
1db73c5
Add deprecation notice for 'behaviors' in image block
artemiomorales Sep 7, 2023
232161a
Add clarifying comment regarding skipped tests
artemiomorales Sep 7, 2023
cabe31b
Do not remove `behaviors` attribute from Image block's block.json.
michalczaplinski Sep 7, 2023
715e32c
Merge branch 'update/revise-lightbox-ui' into update/lightbox-setting…
michalczaplinski Sep 7, 2023
aa4450e
Revert "Do not remove `behaviors` attribute from Image block's block.…
michalczaplinski Sep 7, 2023
41f251d
Merge branch 'update/revise-lightbox-ui' into update/lightbox-setting…
michalczaplinski Sep 7, 2023
79dad34
Add deprecation for attribute in image block
artemiomorales Sep 9, 2023
871ba45
Remove obsolete code now that block deprecation is in place
artemiomorales Sep 10, 2023
7f2f70f
Add support for 'lightbox: true' syntax
artemiomorales Sep 11, 2023
6da3545
Fix lightbox 'checked' attribute being read improperly
artemiomorales Sep 11, 2023
91b86ef
Merge branch 'trunk' into update/revise-lightbox-ui
michalczaplinski Sep 11, 2023
83bef30
Add conditional display for settings panel at image block level
artemiomorales Sep 11, 2023
52e358d
Fix an error with the theme.json schema.
michalczaplinski Sep 11, 2023
11e96e2
Update docs with `npm run build:docs`
michalczaplinski Sep 11, 2023
8809612
Merge branch 'update/revise-lightbox-ui' into update/lightbox-setting…
michalczaplinski Sep 11, 2023
59e0dbe
Copy `class-wp-theme-json-schema.php` from core
michalczaplinski Sep 11, 2023
3eeb1a7
Merge branch 'update/lightbox-settings-panels' of github.com:WordPres…
michalczaplinski Sep 11, 2023
f9e48f4
Revert deletion of behaviors.php
artemiomorales Sep 11, 2023
443aa5b
Add a theme.json migration to v3 away from behaviors and to a new, si…
michalczaplinski Sep 11, 2023
6459d56
Remove the `null` value from lightbox.enabled in `lib/theme.json`
michalczaplinski Sep 11, 2023
203649d
Remove `behaviors` from VALID_TOP_LEVEL_KEYS & VALID_SETTINGS
michalczaplinski Sep 11, 2023
5a37499
Merge branch 'update/revise-lightbox-ui' into update/lightbox-setting…
artemiomorales Sep 11, 2023
0e63890
Revise backwards compatibility for behaviors; add deprecation to bloc…
artemiomorales Sep 11, 2023
8b721a7
Remove outdated comment
michalczaplinski Sep 12, 2023
8287c46
Update outdated comment
michalczaplinski Sep 12, 2023
a2c2b94
Update comment and shuffle the lines so the diff is easier on the eyes.
michalczaplinski Sep 12, 2023
4f0709b
Update comment to explain why we use userSettings in image-settings-p…
michalczaplinski Sep 12, 2023
7018ee7
Remove support for legacy fade configuration
artemiomorales Sep 12, 2023
7fd0801
Resolve lint error
artemiomorales Sep 12, 2023
5bb05bc
Add clarifying comment regarding lightbox markup
artemiomorales Sep 12, 2023
a02910c
Rename the migrate function to reflect that it's not a v3 migration
michalczaplinski Sep 12, 2023
b12d386
Add a `@since` in `gutenberg_should_render_lightbox` docblock
michalczaplinski Sep 12, 2023
2f5f122
Add support for reading top-level 'lightbox' setting in editor
artemiomorales Sep 12, 2023
a238d94
Revert "Add support for reading top-level 'lightbox' setting in editor"
artemiomorales Sep 13, 2023
0aba3c4
Add correct deprecation mentioning the Gutenberg version
michalczaplinski Sep 13, 2023
8fa991e
Move 'allowEditing' to top-level settings
artemiomorales Sep 13, 2023
65b173c
Fix top-level lightbox setting not being read properly
artemiomorales Sep 13, 2023
b5f8186
Fix 'false' values in theme.json not being stored in settings object
artemiomorales Sep 13, 2023
7e121da
Fix error wherein 'undefined' was being passed to input component
artemiomorales Sep 13, 2023
fb10384
Fix bug wherein lightbox UI would disappear if user value was set
artemiomorales Sep 13, 2023
ef8f43e
Remove inheritance when determining whether to enable lightbox
artemiomorales Sep 13, 2023
fc8fc47
Update comment
artemiomorales Sep 13, 2023
6ea39f8
Update whitespace in theme.json
michalczaplinski Sep 14, 2023
aaab1ef
Add docblocks to clarify that `class-wp-theme-json-schema-gutenberg.p…
michalczaplinski Sep 14, 2023
61bfb3d
Add comments to clarify that behaviors.php is temporarily added to GB…
michalczaplinski Sep 14, 2023
c18e283
Added integration fixtures for the lightbox
michalczaplinski Sep 14, 2023
8b95f4a
Merge branch 'trunk' into update/revise-lightbox-ui
michalczaplinski Sep 14, 2023
7d30aa6
Merge branch 'update/revise-lightbox-ui' into update/lightbox-setting…
michalczaplinski Sep 14, 2023
dab7f5a
Fix incorrect reading of global lightbox settings
artemiomorales Sep 14, 2023
a5c2f0c
Clarify the comment getting the global lightbox settings
michalczaplinski Sep 14, 2023
485c197
Fix PHPCS parenthesis error 🤦‍♂️
michalczaplinski Sep 15, 2023
d1432bc
Move lightbox settings to the block level
artemiomorales Sep 15, 2023
ff1d2b5
Remove support for shorthand
artemiomorales Sep 15, 2023
ee1dd8c
Remove 'lightbox' from hooks.js and add `.enabled` & `.allowEditing` …
michalczaplinski Sep 15, 2023
c30fd60
Fix another phpcs error
michalczaplinski Sep 15, 2023
1ffe40b
Merge branch 'trunk' into update/lightbox-settings-panels
artemiomorales Sep 15, 2023
8586f29
Fix phpcs error
artemiomorales Sep 15, 2023
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
11 changes: 5 additions & 6 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

This page lists the blocks included in the block-library package.

- Items marked with a strikeout (~~strikeout~~) are explicitly disabled.
- Blocks marked with **Experimental:** true are only available when Gutenberg is active.
- Blocks marked with **Experimental:** fse are only available in the Site Editor.

- Items marked with a strikeout (~~strikeout~~) are explicitly disabled.
- Blocks marked with **Experimental:** true are only available when Gutenberg is active.
- Blocks marked with **Experimental:** fse are only available in the Site Editor.

<!-- START TOKEN Autogenerated - DO NOT EDIT -->

Expand Down Expand Up @@ -339,8 +338,8 @@ Insert an image to make a visual statement. ([Source](https://github.com/WordPre

- **Name:** core/image
- **Category:** media
- **Supports:** anchor, behaviors (lightbox), color (~~background~~, ~~text~~), filter (duotone)
- **Attributes:** align, alt, aspectRatio, caption, height, href, id, linkClass, linkDestination, linkTarget, rel, scale, sizeSlug, title, url, width
- **Supports:** anchor, color (~~background~~, ~~text~~), filter (duotone)
- **Attributes:** align, alt, aspectRatio, caption, height, href, id, lightbox, linkClass, linkDestination, linkTarget, rel, scale, sizeSlug, title, url, width

## Latest Comments

Expand Down
21 changes: 11 additions & 10 deletions docs/reference-guides/theme-json-reference/theme-json-living.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ Settings related to layout.

---

### lightbox

Settings related to the lightbox.

| Property | Type | Default | Props |
| --- | --- | --- |--- |
| enabled | boolean | | |
| allowEditing | boolean | | |

---

### position

Settings related to position.
Expand Down Expand Up @@ -183,16 +194,6 @@ Settings related to typography.
Generate custom CSS custom properties of the form `--wp--custom--{key}--{nested-key}: {value};`. `camelCased` keys are transformed to `kebab-case` as to follow the CSS property naming schema. Keys at different depth levels are separated by `--`, so keys should not include `--` in the name.


---

### behaviors

Settings related to behaviors.

| Property | Type | Default | Props |
| --- | --- | --- |--- |
| lightbox | boolean | false | |

---
## Styles

Expand Down
16 changes: 15 additions & 1 deletion lib/block-supports/behaviors.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
/**
* Behaviors block support flag.
*
* This file will NOT be backported to Core. It exists to provide a
* migration path for theme.json files that used the deprecated "behaviors".
* This file will be removed from Gutenberg in version 17.0.0.
*
* @package gutenberg
*/

Expand Down Expand Up @@ -37,13 +41,23 @@ function gutenberg_register_behaviors_support( $block_type ) {

/**
* Add the directives and layout needed for the lightbox behavior.
* This functions shouldn't be in this file. It should be moved to a package (or somewhere else), where all the behaviors logic is defined.
*
* @param string $block_content Rendered block content.
* @param array $block Block object.
* @return string Filtered block content.
*/
function gutenberg_render_behaviors_support_lightbox( $block_content, $block ) {

// We've deprecated the lightbox implementation via behaviors.
// While we may continue to explore behaviors in the future, the lightbox
// logic seems very specific to the image and will likely never be a part
// of behaviors, even in the future. With that in mind, we've rewritten the lightbox
// to be a feature of the image block and will also soon remove the block_supports.
// *Note: This logic for generating the lightbox markup has been duplicated and moved
// to the image block's index.php.*
// See https://github.com/WordPress/gutenberg/issues/53403.
_deprecated_function( 'gutenberg_render_behaviors_support_lightbox', 'Gutenberg 17.0.0', '' );

$link_destination = isset( $block['attrs']['linkDestination'] ) ? $block['attrs']['linkDestination'] : 'none';
// Get the lightbox setting from the block attributes.
if ( isset( $block['attrs']['behaviors']['lightbox'] ) ) {
Expand Down
29 changes: 29 additions & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,33 @@ function gutenberg_legacy_wp_block_post_meta( $value, $object_id, $meta_key, $si

return $value;
}

add_filter( 'default_post_metadata', 'gutenberg_legacy_wp_block_post_meta', 10, 4 );

/**
* Complements the lightbox implementation for the 'core/image' block.
*
* This function is INTENTIONALLY left out of core as it only provides
* backwards compatibility for the legacy lightbox syntax that was only
* introduced in Gutenberg. The legacy syntax was using the `behaviors` key in
* the block attrbutes and the `theme.json` file.
*
* @since 16.7.0
*
* @param array $block The block to check.
* @return array The block with the legacyLightboxSettings set if available.
*/
function gutenberg_should_render_lightbox( $block ) {

if ( 'core/image' !== $block['blockName'] ) {
return $block;
}

if ( isset( $block['attrs']['behaviors']['lightbox'] ) ) {
$block['legacyLightboxSettings'] = $block['attrs']['behaviors']['lightbox'];
}

return $block;
}

add_filter( 'render_block_data', 'gutenberg_should_render_lightbox', 15, 1 );
33 changes: 5 additions & 28 deletions lib/class-wp-rest-global-styles-controller-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ public function update_item( $request ) {
*
* @since 5.9.0
* @since 6.2.0 Added validation of styles.css property.
* @since 6.4.0 Added validation of behaviors property.
*
* @param WP_REST_Request $request Request object.
* @return stdClass|WP_Error Prepared item on success. WP_Error on when the custom CSS is not valid.
Expand All @@ -322,7 +321,7 @@ protected function prepare_item_for_database( $request ) {
}
}

if ( isset( $request['styles'] ) || isset( $request['settings'] ) || isset( $request['behaviors'] ) ) {
if ( isset( $request['styles'] ) || isset( $request['settings'] ) ) {
$config = array();
if ( isset( $request['styles'] ) ) {
if ( isset( $request['styles']['css'] ) ) {
Expand All @@ -340,11 +339,6 @@ protected function prepare_item_for_database( $request ) {
} elseif ( isset( $existing_config['settings'] ) ) {
$config['settings'] = $existing_config['settings'];
}
if ( isset( $request['behaviors'] ) ) {
$config['behaviors'] = $request['behaviors'];
} elseif ( isset( $existing_config['behaviors'] ) ) {
$config['behaviors'] = $existing_config['behaviors'];
}
$config['isGlobalStylesUserThemeJSON'] = true;
$config['version'] = WP_Theme_JSON_Gutenberg::LATEST_SCHEMA;
$changes->post_content = wp_json_encode( $config );
Expand All @@ -367,7 +361,6 @@ protected function prepare_item_for_database( $request ) {
*
* @since 5.9.0
* @since 6.2.0 Handling of style.css was added to WP_Theme_JSON.
* @since 6.4.0 Added `behavior` field.
*
* @param WP_Post $post Global Styles post object.
* @param WP_REST_Request $request Request object.
Expand Down Expand Up @@ -411,10 +404,6 @@ public function prepare_item_for_response( $post, $request ) { // phpcs:ignore V
$data['styles'] = ! empty( $config['styles'] ) && $is_global_styles_user_theme_json ? $config['styles'] : new stdClass();
}

if ( rest_is_field_included( 'behaviors', $fields ) ) {
$data['behaviors'] = ! empty( $config['behaviors'] ) && $is_global_styles_user_theme_json ? $config['behaviors'] : new stdClass();
}

$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
Expand Down Expand Up @@ -521,7 +510,6 @@ public function get_collection_params() {
* Retrieves the global styles type' schema, conforming to JSON Schema.
*
* @since 5.9.0
* @since 6.4.0 Added `behaviors` property.
*
* @return array Item schema data.
*/
Expand All @@ -535,28 +523,23 @@ public function get_item_schema() {
'title' => $this->post_type,
'type' => 'object',
'properties' => array(
'id' => array(
'id' => array(
'description' => __( 'ID of global styles config.', 'gutenberg' ),
'type' => 'string',
'context' => array( 'embed', 'view', 'edit' ),
'readonly' => true,
),
'styles' => array(
'styles' => array(
'description' => __( 'Global styles.', 'gutenberg' ),
'type' => array( 'object' ),
'context' => array( 'view', 'edit' ),
),
'settings' => array(
'settings' => array(
'description' => __( 'Global settings.', 'gutenberg' ),
'type' => array( 'object' ),
'context' => array( 'view', 'edit' ),
),
'behaviors' => array(
'description' => __( 'Global behaviors.', 'default' ),
'type' => array( 'object' ),
'context' => array( 'view', 'edit' ),
),
'title' => array(
'title' => array(
'description' => __( 'Title of the global styles variation.', 'gutenberg' ),
'type' => array( 'object', 'string' ),
'default' => '',
Expand Down Expand Up @@ -614,7 +597,6 @@ public function get_theme_item_permissions_check( $request ) { // phpcs:ignore V
* Returns the given theme global styles config.
*
* @since 5.9.0
* @since 6.4.0 Added value for `behaviors` rest field.
*
* @param WP_REST_Request $request The request instance.
* @return WP_REST_Response|WP_Error
Expand Down Expand Up @@ -642,11 +624,6 @@ public function get_theme_item( $request ) {
$data['styles'] = isset( $raw_data['styles'] ) ? $raw_data['styles'] : array();
}

if ( rest_is_field_included( 'behaviors', $fields ) ) {
$raw_data = $theme->get_raw_data();
$data['behaviors'] = isset( $raw_data['behaviors'] ) ? $raw_data['behaviors'] : array();
}

$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
Expand Down
11 changes: 7 additions & 4 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ class WP_Theme_JSON_Gutenberg {
'templateParts',
'title',
'version',
'behaviors',
);

/**
Expand All @@ -347,6 +346,7 @@ class WP_Theme_JSON_Gutenberg {
* `position.fixed` and `position.sticky`.
* @since 6.3.0 Removed `layout.definitions`. Added `typography.writingMode`.
* @since 6.4.0 Added `layout.allowEditing`.
* @since 6.4.0 Added `lightbox`.
* @var array
*/
const VALID_SETTINGS = array(
Expand Down Expand Up @@ -387,6 +387,10 @@ class WP_Theme_JSON_Gutenberg {
'wideSize' => null,
'allowEditing' => null,
),
'lightbox' => array(
'enabled' => null,
'allowEditing' => null,
),
'position' => array(
'fixed' => null,
'sticky' => null,
Expand Down Expand Up @@ -419,7 +423,6 @@ class WP_Theme_JSON_Gutenberg {
'textTransform' => null,
'writingMode' => null,
),
'behaviors' => null,
);

/**
Expand Down Expand Up @@ -618,7 +621,7 @@ public function __construct( $theme_json = array(), $origin = 'theme' ) {
$origin = 'theme';
}

$this->theme_json = WP_Theme_JSON_Schema::migrate( $theme_json );
$this->theme_json = WP_Theme_JSON_Schema_Gutenberg::migrate( $theme_json );
$registry = WP_Block_Type_Registry::get_instance();
$valid_block_names = array_keys( $registry->get_all_registered() );
$valid_element_names = array_keys( static::ELEMENTS );
Expand Down Expand Up @@ -2861,7 +2864,7 @@ protected static function filter_slugs( $node, $slugs ) {
public static function remove_insecure_properties( $theme_json ) {
$sanitized = array();

$theme_json = WP_Theme_JSON_Schema::migrate( $theme_json );
$theme_json = WP_Theme_JSON_Schema_Gutenberg::migrate( $theme_json );

$valid_block_names = array_keys( static::get_blocks_metadata() );
$valid_element_names = array_keys( static::ELEMENTS );
Expand Down
Loading
Loading