Repository navigation
Themes: Add the wideImages theme support config - #2021
Conversation
|
Yaay, thank you for working on this. I'm now not seeing the wide and full wide options running Twenty Seventeen (which is to be expected, that's the point, 👍 👍). I did, however, try to add This PR will also put a fire under us to start blockifying Twenty Seventeen so we have a great example theme that works great with Gutenberg. |
I did try that but directly in the gutenberg code, maybe it's a bug related to the order of function calls (looking) |
|
@jasmussen I just added |
2e487c4 to
b8a1605
Compare
| value={ align } | ||
| onChange={ updateAlignment } | ||
| controls={ validAlignments } | ||
| controls={ [ 'left', 'center', 'right' ].concat( settings.wideImages ? [ 'wide', 'full' ] : [] ) } |
There was a problem hiding this comment.
Should we bake this into the BlockAlignmentToolbar component, since it already has some knowledge of wide and full widths? Maybe as a boolean prop.
| // Initialize the editor. | ||
| wp_add_inline_script( 'wp-editor', 'wp.api.init().done( function() { wp.editor.createEditorInstance( \'editor\', window._wpGutenbergPost ); } );' ); | ||
| $editor_settings = array( | ||
| 'wideImages' => get_theme_support( 'wide-images' ), |
There was a problem hiding this comment.
- Instead of one-off theme supports, we might consider a single umbrella theme support key, whose values is an array with one or more of
wide-images, etc? Depends if we think "wide-images" has value as a theme support outside just the editor. - What about themes which support full images, but not wide, or vice-versa? Should we be more granular here?
There was a problem hiding this comment.
Good questions, I'm happy to use whatever we settle on. So you're proposing something like:
add_theme_support( 'gutenberg-theme-support', [ 'wide-images' ] );I kind of like the one liner if you want to enable a feature (I mean the current approach) but no strong opinion here. cc @jasmussen
There was a problem hiding this comment.
Oh! I just saw the proposals down here. This is already answered in a way.
| 'wideImages' => get_theme_support( 'wide-images' ), | ||
| ); | ||
| wp_add_inline_script( 'wp-editor', 'wp.api.init().done( function() {' | ||
| . 'wp.editor.createEditorInstance( \'editor\', window._wpGutenbergPost, ' . json_encode( $editor_settings ) . ' ); ' |
There was a problem hiding this comment.
Above we're already creating a global object via wp_localize_script, used to initialize TinyMCE settings. I like in this case that we're more explicit about passing an options object to the createEditorInstance (vs. assuming globals from code itself), but wondering if we should merge $editor_settings into wpEditorL10n and pass this object from the corresponding property e.g. wpEditorL10n.settings
There was a problem hiding this comment.
Instead of moving more values to the global wpEditorL10n should we not opt to move more values into the object being passed into createEditorInstance? I think we should eliminate wp_localize_script() and explicitly pass what is being exported as wpEditorL10n into the editor here as well. There's going to be a need to export more data from PHP into the editor, such as the server's date formatting in #2013. So the more that we can establish a single pattern for getting data from PHP into JS the better.
There was a problem hiding this comment.
I think there's a global reflection to have here the more we create JS UI. (not only Gutenberg).
A proposal could be:
- if you need
dateand you enqueuewp-dateyou automatically get awpDateSettingsglobal variable. - if you need
i18nand you enqueuewp-i18nyou automatically get awpI18nSettingsglobal. - if you need
themes supportand you enqueuewp-themesyou getwpThemeSettingsglobal.
I don't if this proposal is good but we need to find a consistent way of retrieving these settings. An automatically injected global variable or an endpoint (the first one is more "reactive" and performant I guess)
But at the same time, I'd like us to avoid the globals in the Editor Code itself (to make it reusable), so a settings variable in createEditorInstance makes sense to me and could be computed using these globals.
There was a problem hiding this comment.
But at the same time, I'd like us to avoid the globals in the Editor Code itself (to make it reusable), so a
settingsvariable increateEditorInstancemakes sense to me and could be computed using these globals.
Yes! I was thinking something similar. So perhaps each individual script could export to a global, but then we could use jQuery.extend() to merge them together just-in-time. For example:
wp_add_inline_script( 'wp-editor',
sprintf(
'wp.api.init().done( function() { wp.editor.createEditorInstance( "editor", %s ); } );',
sprintf( 'jQuery.extend( {},
{ post: window._wpGutenbergPost },
{ date: wpDateSettings },
{ i18n: wpI18nSettings },
{ themes: wpThemeSettings },
{ editor: %s } )',
wp_json_encode( $editor_settings )
)
)
);If wp-editor depends on wp-date, wp-i18n, wp-themes, any other scripts to which the corresponding globals are attached, then all of these globals will be guaranteed to have already been output to the browser and we'd be able to refer to them. We'd then eliminate the reliance on global variables.
| import Layout from './layout'; | ||
| import { createReduxStore } from './state'; | ||
|
|
||
| const defaultSettings = { |
There was a problem hiding this comment.
Can we use SCREAMING_SNAKE_CASE for constants? Also a DocBlock comment would be a nice addition (though it's admittedly fairly self-explanatory, for consistency's / habit's / self-enforcement's sake).
|
See also: https://codex.wordpress.org/Plugin_API/Action_Reference In my testing, adding and removing |
|
Let's do something that could include further items, like colors, width, etc, via |
There are limitations in the theme supports API here, specifically when making multiple calls to // Parent:
add_theme_support( 'gutenberg', array(
'wide-images' => true,
) );
// Child
add_theme_support( 'gutenberg', array(
'colors' => true,
) );
// Result:
get_theme_support( 'gutenberg' ) == array( 'colors' => true ); // FAILSo if this were done, then if child themes ever added theme support, they'd have to always do this: add_theme_support( 'gutenberg', array_merge(
(array) get_theme_support( 'gutenberg' ),
array(
'colors' => true,
)
) );Which isn't great. |
b8a1605 to
5f84aa1
Compare
|
@westonruter has some good points here, should we stick with an individual key for each theme support? |
|
@davidakennedy @obenland what are your thoughts? |
|
While it's true that "adding" theme support in a child theme doesn't really add to but overwrites a parent's theme support, I still think that Gutenberg-related support clauses should be bundled in a common namespace. The amount of features themes can add support for are already getting unwieldy, let not add to that. I don't see why it couldn't work like |
373e246 to
ce89e3b
Compare
|
Ok the majority wins ;) updated to use this syntax: add_theme_support( 'gutenberg', array(
'wide-images' => true,
) ); |
ce89e3b to
3552bc5
Compare
Codecov Report
@@ Coverage Diff @@
## master #2021 +/- ##
==========================================
+ Coverage 20.25% 20.34% +0.08%
==========================================
Files 135 135
Lines 4227 4233 +6
Branches 718 721 +3
==========================================
+ Hits 856 861 +5
+ Misses 2842 2841 -1
- Partials 529 531 +2
Continue to review full report at Codecov.
|
|
Since this will remove some of the most prominent toolbar options, let's wait until next week so we can have a basic theme to go along with it. |
…me support features
3552bc5 to
77fde94
Compare
|
pinging @karmatosed because I believe you're working on a Gutenberg Theme? I'm willing to merge this but I'm waiting for a theme implementing it :) |
|
@youknowriad just added it here: WordPress/gutenberg-starter-theme#5. Thanks for ping, I think I got the syntax right? Does it still use the same CSS class? |
|
👍 cool, let's merge this one then. The classes are unchanged. |
|
|
||
| ### Wide Images: | ||
|
|
||
| Some blocks such as the image block have the possibility to define a "wide" or "full" alignment by adding the corresponding classname to the block's wrapper ( `alignwide` or `alignfull` ). A theme can opt-in for this feature by calling: |
There was a problem hiding this comment.
When should they call this? ?after_setup_theme?
There was a problem hiding this comment.
Yes. This is when the core-bundled themes call add_theme_support()
There was a problem hiding this comment.
Right, we should document as such.
closes #1724
The backend passes an
editorSettingsvariable when initializing the editor. This object could contain any global editor setting such as thewideImagesflag for now.I'm storing these settings in the editor's store but we could decide to pass it as prop down to where it's being used.
By default, the
wideImagesis disabled and we could opt-in by callingadd_theme_support( 'wide-images' );