Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class 'Drupal\bootstrap\Bootstrap' not found error #69

Open
henokmikre opened this issue May 27, 2021 · 8 comments
Open

Class 'Drupal\bootstrap\Bootstrap' not found error #69

henokmikre opened this issue May 27, 2021 · 8 comments

Comments

@henokmikre
Copy link

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 of SwaggerUiLibraryDiscovery.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.

@mxr576
Copy link
Collaborator

mxr576 commented Jul 27, 2022

Thanks for the D.o issue references but you can explain the steps to reproduce this problem by using the Swagger UI FF module?

@driverok
Copy link

driverok commented Dec 1, 2022

Steps might be the following

  1. Clear the cache
  2. Go to any non-admin page (ex. homepage)
  3. Go to /admin/config or /admin/reports/status page.
  4. The message comes up that Bootstrap class can not be found:
  5. Clear cache again
  6. Go to /admin/config or /admin/reports/status page.
  7. Pages are loading without any issues.

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:

  1. Add listInfo() method call inside of libraryDirectory() method
  2. Programmatically clear theme cache before getActiveThemeByName() call
  3. Register theme classes manually

Option 1 as for me looks more promising.

@mxr576
Copy link
Collaborator

mxr576 commented Dec 1, 2022

Can anybody reproduce this issue with ANY other theme than bootstrap? (Because Drupal\bootstrap\Bootstrap is a class from that theme). Themes vs autoloading in Drupal is just weird...

@mxr576
Copy link
Collaborator

mxr576 commented Dec 1, 2022

@alenastanul87
Copy link

alenastanul87 commented Jan 31, 2023

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

@mxr576
Copy link
Collaborator

mxr576 commented Feb 2, 2023

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:

  • Fixes like you proposed can be on any downstream project by decorating the swagger_ui_formatter.swagger_ui_library_discovery.
  • The suggested patch looks quite invasitve or resource hungry, Based on what you have shared, calling \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?

@alenastanul87
Copy link

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.

@mxr576
Copy link
Collaborator

mxr576 commented Feb 3, 2023

Quick answer before I leave for the weekend :) Could you please create a PR instead of sharing suggestions in patches? thank you

alenastanul87 added a commit to alenastanul87/swagger_ui_formatter that referenced this issue Feb 6, 2023
alenastanul87 added a commit to alenastanul87/swagger_ui_formatter that referenced this issue Feb 6, 2023
alenastanul87 added a commit to alenastanul87/swagger_ui_formatter that referenced this issue Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants