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

Try/font family optionally upload assets #57989

Open
wants to merge 15 commits into
base: trunk
Choose a base branch
from

Conversation

pbking
Copy link
Contributor

@pbking pbking commented Jan 19, 2024

What?

Update the Font Collection object to contain a require_download property
Add an editor setting of fontLibraryAssetInstall
Install (download, then upload) fonts when appropriate
Use hosted font face assets when appropriate
Hide Tabs (upload or specific font collections) when appropriate

The fontLibraryAssetInstall can be set to the values:

  • require : Require all Font Faces to be installed. This is the default. All Font Faces will always be installed.
  • allow : Allow Font Faces to be installed. Font Collections that can be hosted (require_download === FALSE) will be hosted, Font Collections that must be installed (require_download === TRUE) will be installed.
  • denied: Font Faces are not allowed to be installed into the system. The UPLOAD tab will be hidden. Any Font Collections that require installation (require_download === TRUE) will not be shown.

The value of fontLibraryAssetInstall can be set like this in PHP:

function set_font_library_asset_install_value( $editor_settings ) { 
	$editor_settings['fontLibraryAssetInstall'] = 'denied';
    return $editor_settings; 
}

add_filter( "block_editor_settings_all", "set_font_library_asset_install_value" );

Each Font Collection require_download property is set when the collection is created.

$default_font_collection = array(
	'slug'             => 'default-font-collection',
	'require_download' => false,
	'name'             => 'Google Fonts',
	'description'      => __( 'Add from Google Fonts. Fonts are copied to and served from your site.', 'gutenberg' ),
	'src'              => 'https://s.w.org/images/fonts/16.7/collections/google-fonts-with-preview.json',
);

Testing Instructions

When fontLibraryAssetInstall is denied
the UPLOAD tab is hidden
any collection with require_download set to TRUE is hidden

When fontLibraryAssetInstall is required:
the UPLOAD tab is available
All font assets are installed from any font collection

When fontLibraryAssetInstall is allowed:
the UPLOAD tab is available
any font faces installed from a collection with require_download set to TRUE is installed
any font faces installed from a collection with require_download set to FALSE is NOT installed

NOTE: While working on this I noticed that the calls to load individual Font Collections was unnecessary (that data is loaded when all of the font collections are loaded) and has been removed.

creativecoder and others added 15 commits January 12, 2024 13:37
…arent (#57867)

Co-authored-by: Sarah Norris <1645628+mikachan@users.noreply.github.com>
…ised API (#57844)

* Add batchInstallFontFaces function and related plumbing.

* Fix resolver name.

* Add embedding and rebuild theme.json settings for fontFamily.

* Handle responses directly, add to collection before activating. Remove unused test.

* Remove getIntersectingFontFaces.

* Check for existing font family before installing.

* Reference src, not uploadedFile key.

Co-authored-by: Matias Benedetto <matias.benedetto@gmail.com>

* Check for existing font family using GET /font-families?slug=.

* Filter already installed font faces (determined by matching fontWeight AND fontStyle)

---------

Co-authored-by: Matias Benedetto <matias.benedetto@gmail.com>
Co-authored-by: Jason Crist <jcrist@pbking.com>
* Add batchInstallFontFaces function and related plumbing.

* Fix resolver name.

* Add embedding and rebuild theme.json settings for fontFamily.

* Handle responses directly, add to collection before activating. Remove unused test.

* Remove getIntersectingFontFaces.

* Check for existing font family before installing.

* Reference src, not uploadedFile key.

Co-authored-by: Matias Benedetto <matias.benedetto@gmail.com>

* Check for existing font family using GET /font-families?slug=.

* Filter already installed font faces (determined by matching fontWeight AND fontStyle)

* moved response processing into the resolver for fetchGetFontFamilyBySlug

* Moved response processing for font family installation to the resolver

* Refactored font face installation process to handle errors more cleanly

* Cleanup error handling for font library view

* Add i18n function to error messages

* Add TODO comment for uninstall notice

---------

Co-authored-by: Jeff Ong <jonger4@gmail.com>
Co-authored-by: Matias Benedetto <matias.benedetto@gmail.com>
Co-authored-by: Sarah Norris <sarah@sekai.co.uk>
* Fix delete endpoint

* Update fetchUninstallFontFamily to match new format

* Update uninstallFont

* Add uninstall notice back in

* Tidy up comments

* Re-word uninstall notices

* Add spacing to error message

* Refactored how font family values were processed so they would retain their id, which is now used to delete a font family without fetching data via slug

* Rename uninstallFont to uninstallFontFamily

* Throw uninstall errors rather than returning them

---------

Co-authored-by: Jason Crist <jcrist@pbking.com>
…odal/local-fonts.js

Co-authored-by: Jonny Harris <spacedmonkey@users.noreply.github.com>
…fontLibraryAssetInstall and a font collection's require_download value
Copy link

github-actions bot commented Jan 19, 2024

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core.
  • Labels found: [Feature] Typography.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

Copy link
Contributor

@jffng jffng left a comment

Choose a reason for hiding this comment

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

This tests as expected according to the instructions. I have a few comments:

  1. I'm pretty confused at the naming. (It's a tricky one!) In particular —  fontFamilyAssetInstall = allow and require_download = false means that the font face's src will be copied from the collection, as is. That feels pretty opaque.
  2. If we do go with one editor setting with three options, could the names be present tense and consistent? I.e. allow, deny, require.
  3. I think this will conflict with Font Library: font collection refactor to use the new schema #57884, particularly the removal of the getFontCollection function, so perhaps that one should come in first.

const fontFamily = fontsToInstall[ 0 ];
let fontFamily = fontsToInstall[ 0 ];

//NOTE: This is only necessary while the collection potentially includes the depreciated 'downloadFromUrl' property.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//NOTE: This is only necessary while the collection potentially includes the depreciated 'downloadFromUrl' property.
// TODO: Remove mapping once 'downloadFromUrl' property is deprecated.

return fontFace;
} );
}
////////////
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this to indicate what chunk of code can be removed once downloadFromURL is deprecated? I think it's clear enough without it.

@@ -153,34 +140,67 @@ function FontCollection( { id } ) {
setFontsToInstall( [] );
};

const handleFontDownload = async ( fontFamily ) => {
return Promise.all(
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the last discussion we had about async, does this need to await?

Suggested change
return Promise.all(
return await Promise.all(

Comment on lines 76 to 82
export async function fetchFontCollection( id ) {
const config = {
path: `/wp/v2/font-collections/${ id }`,
method: 'GET',
};
return apiFetch( config );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this function being removed?

Copy link
Contributor

@matiasbenedetto matiasbenedetto Jan 19, 2024

Choose a reason for hiding this comment

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

Ohh I found why in this comment:

NOTE: While working on this, I noticed that the calls to load individual Font Collections were unnecessary (that data is loaded when all of the font collections are loaded) and have been removed.

I think that should not be like that because the initial /font-collections/ request would be unnecessarily heavy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Typography Font and typography-related issues and PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants