Problem/Motivation

#2983843: Do not show help text suggesting installing default module if depencies is not met moved a part of search_api_db_defaults_requirements() to \Drupal\search_api\IndexListBuilder(). However, this class is not available when the Search API module has not been enabled yet. This causes a fatal error:

Error: Class 'Drupal\search_api\IndexListBuilder' not found in search_api_db_defaults_requirements() (line 17 of /[...]/modules/search_api/modules/search_api_db/search_api_db_defaults/search_api_db_defaults.install)

Proposed resolution

Fix the fatal error when Database Search Defaults is enabled before the Search API.

Remaining tasks

  1. Write a patch
  2. Review
  3. Commit

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

idebr created an issue. See original summary.

herved’s picture

I can confirm the issue on a fresh 8.6.9 install.
Here is a patch using drupal_classloader_register() which works but I don't know for sure if this is the right way.

herved’s picture

Status: Active » Needs review
quietone’s picture

I too am getting this error. Sorry, not able to test patch now.

drunken monkey’s picture

Component: General code » Defaults module
StatusFileSize
new2.51 KB
new1.33 KB
new2.38 KB

Ah, damn, that makes sense … Really tricky to use the same code during installation and without having the module installed.
At least drupal_get_path() already works there, that’s something. Otherwise, this would be even harder to fix. But as it looks, your proposed patch seems to be a very sensible solution.

However, since manually registering class loading seems pretty hack-ish to me, perhaps we should go with a more minimal approach, of only loading that one class. Seems to work fine, too.
I also added test coverage for this in the attached patch – please test/review!

vinlaurens’s picture

Status: Needs review » Reviewed & tested by the community

I have tested the patch above and can confirm that the error does not occur anymore.

Steps I performed:

- Clean Drupal 8.6.10 install.
- Composer require drupal/search_api
- Enable "Database Search", "Database search defaults" and "Search API" at the same time.
- Got following error:

The website encountered an unexpected error. Please try again later.
Error: Class 'Drupal\search_api\IndexListBuilder' not found in search_api_db_defaults_requirements() (line 19 of modules/contrib/search_api/modules/search_api_db/search_api_db_defaults/search_api_db_defaults.install).
search_api_db_defaults_requirements('install')
call_user_func_array('search_api_db_defaults_requirements', Array) (Line: 392)
Drupal\Core\Extension\ModuleHandler->invoke('search_api_db_defaults', 'requirements', Array) (Line: 1035)
drupal_check_module('search_api_db_defaults') (Line: 419)
Drupal\system\Form\ModulesListForm->buildModuleList(Object) (Line: 437)
Drupal\system\Form\ModulesListForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder->processForm('system_modules', Array, Object) (Line: 318)
Drupal\Core\Form\FormBuilder->buildForm('system_modules', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

- Made sure "Database Search", "Database search defaults" and "Search API" are disabled.
- Applied the patch in #5 with "patch -p1 < 3033040-5--db_defaults_module_install_error.patch"
- Enabled modules "Database Search", "Database search defaults" and "Search API" are disabled.
- Error is not occurring anymore.

  • drunken monkey committed ff1b065 on 8.x-1.x authored by herved
    Issue #3033040 by herved, drunken monkey, vinlaurens: Fixed error when...
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Awesome, thanks a lot for testing!
Committed.
Thanks again, everyone!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.