Needs review
Project:
Gutenberg
Version:
3.0.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
25 Aug 2021 at 16:03 UTC
Updated:
19 Feb 2025 at 13:30 UTC
Jump to comment: Most recent
When adding images in Gutenberg we see all the image styles available. With so many modules adding their own images styles this can be overwhelming for the user.
This experience has been improved with the work done in #3340209: Limit available image styles for image related blocks, but it's still useful if there's a way to systematically restrict who has access to the styles in a more modular fashion e.g. via permissions.
Add a hook in Gutenberg to allow custom modules to restrict image styles shown.
\Drupal::moduleHandler()->alter('gutenberg_image_styles', $sizes);
Example usage
// remove thumbnail style from Gutenberg
function MYMODULE_gutenberg_image_styles_alter(array &$sizes) {
// Never allow access to the thumbnail style.
unset($sizes['thumbnail']);
$user = \Drupal::currentUser();
foreach ($sizes as $style => $value) {
// Check if the current user has custom permission to access this particular style.
if (!$user->hasPermission('access image style for ' . $style)) {
unset($sizes[$style]);
}
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| gutenberg-allow-image-styles-to-be-overridden.patch | 416 bytes | ghaddon |
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ghaddon commentedComment #3
bessonweb commentedI think it will be a good thing to can restrict the image styles are available.
But if we can do that by the .gutenberg.yml in the theme folder, I think it's better than create a custom module.
I hope somebody could make this.
Comment #4
codebymikey commentedComment #6
codebymikey commentedProvided a MR restricting the loaded image styles.