- Issue created by @perandre
- First commit to issue fork.
- π΅πΉPortugal fabioneves
Adds an accordion to the "Gutenberg Experience" settings on content type edit screen with an option to filter allowed image styles.
- π΅πΉPortugal fabioneves
Adds missing code to filter image sizes in gutenberg sidebar
- π΅πΉPortugal fabioneves
Fixes 'original' being shown when it's not selected in allowed styles
Thanks for working on this! This capability would be great!
I installed the patch #6 and got the following error:
Warning: foreach() argument must be of type array|object, null given in gutenberg_form_alter() (line 281 of /var/www/html/web/modules/contrib/gutenberg/gutenberg.module)
#0 /var/www/html/web/core/includes/bootstrap.inc(347): _drupal_error_handler_real(2, 'foreach() argum...', '/var/www/html/w...', 281)
#1 /var/www/html/web/modules/contrib/gutenberg/gutenberg.module(281): _drupal_error_handler(2, 'foreach() argum...', '/var/www/html/w...', 281)
#2 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(562): gutenberg_form_alter(Array, Object(Drupal\Core\Form\FormState), 'node_type_edit_...')
#3 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(838): Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object(Drupal\Core\Form\FormState), 'node_type_edit_...')
#4 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(282): Drupal\Core\Form\FormBuilder->prepareForm('node_type_edit_...', Array, Object(Drupal\Core\Form\FormState))
#5 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\node\NodeTypeForm), Object(Drupal\Core\Form\FormState))
#6 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#7 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#8 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#9 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#10 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#11 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(169): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#12 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#13 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#22 {main}The list to select the image styles did work, and in gutenberg the options are only showing what I chose, but the image style is not being applied when i save the page.
- π΅π±Poland kjankowski Warsaw
Added a small fix that will prevent showing warnings in the editor whenever a new image style is added.
- Status changed to RTBC
8 months ago 11:24am 3 June 2024 - π³π΄Norway TwiiK Trondheim
Here's the patch in #8 rerolled for Gutenberg 3.0.
We've been running that patch for ages now.
- First commit to issue fork.
-
marcofernandes β
committed f9612127 on 8.x-2.x
Resolve #3340209 "Limit available image"
-
marcofernandes β
committed f9612127 on 8.x-2.x
- Merge request !179Issue #3340209 by fabioneves: Limit available image styles for image related blocks β (Merged) created by marcofernandes
-
marcofernandes β
committed 4a44271e on 3.0.x
Issue #3340209 by fabioneves: Limit available image styles for image...
-
marcofernandes β
committed 4a44271e on 3.0.x
- Status changed to Fixed
6 months ago 1:14pm 9 August 2024 - π΅πΉPortugal marcofernandes
Finally merged to 2.x and 3.0.x. Great work y'all π
- πΊπΈUnited States tkiehne
Just a notice for anyone who gets a warning message as follows after upgrading to 3.0.3:
Warning: Undefined variable $sizes in gutenberg_form_node_form_alter() (line 765 of modules/contrib/gutenberg/gutenberg.module).
You will need to re-save the content type configuration for all content types using Gutenberg to set the allowed styles and clear this warning.
- π©πͺGermany szeidler Berlin
@tkiehne This has fixed in π Undefined variable $sizes in gutenberg_form_node_form_alter() Fixed .
But I have another one as well, if you just updated without saving all node forms again.
Warning: Trying to access array offset on null in /var/www/html/web/modules/contrib/gutenberg/gutenberg.module on line
So it's actually better to do the following
$allowed_styles = $config->get($node_type . '_allowed_image_styles') ?? [];
In addition there is the following:
if (!empty($styles)) { foreach ($styles as $style) { if ($allowed_styles[$style->getName()]) { $sizes[] = [ 'slug' => $style->getName(), 'name' => $style->label(), ]; } } }
If the site introduces a new image style after the node form has been saved, this will also lead to a warning.
-
marcofernandes β
committed 4a44271e on 4.0.x
Issue #3340209 by fabioneves: Limit available image styles for image...
-
marcofernandes β
committed 4a44271e on 4.0.x
-
szeidler β
committed a57338fa on 8.x-2.x
Issue #3340209: Fix undefined index warning on allowed image styles
-
szeidler β
committed a57338fa on 8.x-2.x
Automatically closed - issue fixed for 2 weeks with no activity.
There's a new issue caused by this change: π Warning: Trying to access array offset on value of type null in gutenberg_form_node_form_alter() (line 578 of gutenberg.module). Active
I explained my findings here: https://www.drupal.org/project/gutenberg/issues/3471570#comment-15786262 π Warning: Trying to access array offset on value of type null in gutenberg_form_node_form_alter() (line 578 of gutenberg.module). Active