Open henokmikre opened 3 years ago
Thanks for the D.o issue references but you can explain the steps to reproduce this problem by using the Swagger UI FF module?
Steps might be the following
Error: Class 'Drupal\bootstrap\Bootstrap' not found in include_once() (Line: 147) Drupal\Core\Extension\Extension->load() (Line: 35) twig_init() call_user_func() (Line: 144) Drupal\Core\Theme\ThemeInitialization->loadActiveTheme() (Line: 111) Drupal\swagger_ui_formatter\Service\SwaggerUiLibraryDiscovery->libraryDirectory() (Line: 40) swagger_ui_formatter_requirements() call_user_func_array() (Line: 403) Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 111) Drupal\system\SystemManager->listRequirements() (Line: 49) Drupal\system\Controller\SystemInfoController->status() call_user_func_array() (Line: 123) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573) Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151) Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 68) Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 67) Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle() (Line: 57) Drupal\Core\StackMiddleware\Session->handle() (Line: 47) Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106) Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85) Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 47) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 52) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23) Stack\StackedHttpKernel->handle() (Line: 708) Drupal\Core\DrupalKernel->handle() (Line: 19)
As a solution:
Option 1 as for me looks more promising.
I guess this is their dirty trick which is not working in all cases... https://git.drupalcode.org/project/bootstrap/-/blob/8.x-4.x/autoload-fix.php https://git.drupalcode.org/project/bootstrap/-/blob/8.x-4.x/src/Traits/FormAutoloadFixTrait.php#L25
The problem is still reproducible. Main root cause, that the registration the namespaces of installed themes is separately from registration a list of namespaces with PSR-4 directories from container.namespaces. There is a drupal.org issue on this problem. Therefore, while there are no fixes in the core about this problem, the attached patch can be applied: swagger_ui_formatter_fixed_bootstrap_class_not_found_69.patch
Thanks @alenastanul87 for the detailed root cause analyzes.
However, I am still hasitant to commit any changes related to this issue to the module if only Bootstrap based themes are affected. Currently, we are not aware of any other way to trigger this error...
Being that said:
swagger_ui_formatter.swagger_ui_library_discovery
.\Drupal\Core\Extension\ThemeHandler::addTheme()
just for the default theme (instead of ALL installed theme) in \Drupal\swagger_ui_formatter\Service\SwaggerUiLibraryDiscovery::libraryDirectory()
should be enough, isn't it?Thanks @mxr576 for your comment.
Firstly, I compared the page load speed with the code $this->themeHandler->listInfo()
and without. I didn't find a difference. It's worth noting there is a handling cache in getList() function.
Secondly, the problem exists until now. We are facing it. But the work on the drupal.org issue has been going on since 2018. Looking optimistically it will ever be completed. But we don't know the date yet.
Thirdly, considering your comments I propose another version of the patch: swagger_ui_formatter_fixed_bootstrap_class_not_found_with_catching_69.patch.
Quick answer before I leave for the weekend :) Could you please create a PR instead of sharing suggestions in patches? thank you
I noticed this error after upgrading to version 3 (3.2 to be specific). Although the problem is ultimately a core issue, it is more frequently evident since swagger_ui_formatter now calls
loadActiveTheme()
around line 111 ofSwaggerUiLibraryDiscovery.php
. The issue has been reported in drupal.org/i/2667062 and in drupal.org/i/2853398. There was a suggestion that it happens if "rebuild theme" is checked in devel, but I have noticed it even with that option unchecked. I am wondering if anyone has a suggestion for a workaround.