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

Background image: add support for relative theme path URLs in top-level theme.json styles #61271

Merged
merged 25 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
514e7b9
This initial commit:
ramonjd May 1, 2024
fa9e75f
For testing purposes, resolve in get_merged_data - should it be optio…
ramonjd May 1, 2024
2ba6cfd
Rollback test of imperative method in resolver
ramonjd May 1, 2024
17048c3
Moves resolution of file paths back to theme_json resolver
ramonjd May 7, 2024
88aac46
Backend resolution of theme file URIs for global styles.
ramonjd May 8, 2024
4137b37
Working on revisions
ramonjd May 9, 2024
57cd28c
So my linter is working again
ramonjd May 10, 2024
06c2bb0
Changed the relative link to `wp:theme-file-uris`
ramonjd May 13, 2024
3e283e0
Added some explanatory TODOs
ramonjd May 13, 2024
1752858
Adding valid link attributes to the _link object.
ramonjd May 14, 2024
98de1c6
Added some unit tests for utils
ramonjd May 14, 2024
70c26ba
Switching to using file: prefix, which is an established theme.json c…
ramonjd May 16, 2024
b94a512
Fix linting
andrewserong May 18, 2024
efae7f2
Remove TODO
ramonjd May 18, 2024
eb4ab0f
Update tests
ramonjd May 18, 2024
b0fb937
dump var_dump
ramonjd May 18, 2024
7c083bc
Check for $theme_json before resolving
ramonjd May 18, 2024
17d51bd
be explicit about the background value file:./
ramonjd May 18, 2024
60c8bb1
Remove unnecessary empty check
ramonjd May 18, 2024
dd07557
Abstracting getting any resolved URI to separate hook
ramonjd May 18, 2024
26866fc
Update lib/class-wp-theme-json-resolver-gutenberg.php
noisysocks May 18, 2024
f01dcdf
Update lib/class-wp-theme-json-resolver-gutenberg.php
noisysocks May 18, 2024
25f8754
Revert useGlobalStyle changes - no longer required given the new hook
ramonjd May 19, 2024
7fecf34
Bad revert
ramonjd May 19, 2024
5d3ba0b
Rename wp:theme-file-uris to wp:theme-file
ramonjd May 20, 2024
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
Prev Previous commit
Rename wp:theme-file-uris to wp:theme-file
Rename utils file
  • Loading branch information
ramonjd committed May 20, 2024
commit 5d3ba0b0a15e0f5677bba6f23ff5c494df406a54
6 changes: 3 additions & 3 deletions lib/class-wp-rest-global-styles-controller-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public function prepare_item_for_response( $post, $request ) { // phpcs:ignore V
if ( $theme_json ) {
$resolved_theme_uris = WP_Theme_JSON_Resolver_Gutenberg::get_resolved_theme_uris( $theme_json );
if ( ! empty( $resolved_theme_uris ) ) {
$links['https://api.w.org/theme-file-uris'] = $resolved_theme_uris;
$links['https://api.w.org/theme-file'] = $resolved_theme_uris;
}
}
$response->add_links( $links );
Expand Down Expand Up @@ -643,7 +643,7 @@ public function get_theme_item( $request ) {
);
$resolved_theme_uris = WP_Theme_JSON_Resolver_Gutenberg::get_resolved_theme_uris( $theme );
if ( ! empty( $resolved_theme_uris ) ) {
$links['https://api.w.org/theme-file-uris'] = $resolved_theme_uris;
$links['https://api.w.org/theme-file'] = $resolved_theme_uris;
}

$response->add_links( $links );
Expand Down Expand Up @@ -712,7 +712,7 @@ public function get_theme_items( $request ) {
if ( ! empty( $resolved_theme_uris ) ) {
$data->add_links(
array(
'https://api.w.org/theme-file-uris' => $resolved_theme_uris,
'https://api.w.org/theme-file' => $resolved_theme_uris,
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function prepare_item_for_response( $post, $request ) {
$links = array();
$resolved_theme_uris = WP_Theme_JSON_Resolver_Gutenberg::get_resolved_theme_uris( $theme_json );
ramonjd marked this conversation as resolved.
Show resolved Hide resolved
if ( ! empty( $resolved_theme_uris ) ) {
$links['https://api.w.org/theme-file-uris'] = $resolved_theme_uris;
$links['https://api.w.org/theme-file'] = $resolved_theme_uris;
}
$response->add_links( $links );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { TOOLSPANEL_DROPDOWNMENU_PROPS } from './utils';
import { setImmutably } from '../../utils/object';
import MediaReplaceFlow from '../media-replace-flow';
import { store as blockEditorStore } from '../../store';
import { getResolvedThemeFilePath } from './set-theme-file-uris';
import { getResolvedThemeFilePath } from './theme-file-uri-utils';

const IMAGE_BACKGROUND_TYPE = 'image';
const DEFAULT_CONTROLS = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/**
* Internal dependencies
*/
import setThemeFileUris, {
import {
setThemeFileUris,
getResolvedThemeFilePath,
} from '../set-theme-file-uris';
} from '../theme-file-uri-utils';

const themeFileURIs = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function setMutably( object, path, value ) {
* @param {Array<Object>} themeFileURIs A collection of absolute theme file URIs and their corresponding file paths.
* @return {Object} Returns mutated object.
*/
export default function setThemeFileUris( themeJson, themeFileURIs ) {
export function setThemeFileUris( themeJson, themeFileURIs ) {
if ( ! themeJson?.styles || ! themeFileURIs ) {
return themeJson;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { LAYOUT_DEFINITIONS } from '../../layouts/definitions';
import { getValueFromObjectPath, setImmutably } from '../../utils/object';
import BlockContext from '../block-context';
import { unlock } from '../../lock-unlock';
import setThemeFileUris from './set-theme-file-uris';
import { setThemeFileUris } from './theme-file-uri-utils';

// List of block support features that can have their related styles
// generated under their own feature level selector rather than the block's.
Expand Down Expand Up @@ -1220,7 +1220,7 @@ export function useGlobalStylesOutputWithConfig( mergedConfig = {} ) {
const [ blockGap ] = useGlobalSetting( 'spacing.blockGap' );
mergedConfig = setThemeFileUris(
mergedConfig,
mergedConfig?._links?.[ 'wp:theme-file-uris' ]
mergedConfig?._links?.[ 'wp:theme-file' ]
);
const hasBlockGapSupport = blockGap !== null;
const hasFallbackGapSupport = ! hasBlockGapSupport; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback styles support.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function BackgroundPanel() {
headerLabel={ __( 'Image' ) }
defaultValues={ BACKGROUND_DEFAULT_VALUES }
defaultControls={ defaultControls }
themeFileURIs={ _links?.[ 'wp:theme-file-uris' ] }
themeFileURIs={ _links?.[ 'wp:theme-file' ] }
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ public function test_get_theme_items() {
$expected = array(
array(
'_links' => array(
'curies' => array(
'curies' => array(
array(
'name' => 'wp',
'href' => 'https://api.w.org/{rel}',
'templated' => true,
),
),
'wp:theme-file-uris' => array(
'wp:theme-file' => array(
array(
'href' => 'http://localhost:8889/wp-content/themes/emptytheme/img/1024x768_emptytheme_test_image.jpg',
'name' => 'file:./img/1024x768_emptytheme_test_image.jpg',
Expand Down
Loading