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, 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]);
}
}
}
Active
2.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.