Problem/Motivation
Steps to reproduce
- Install jsonapi_extras and enable
- Browse to the overrides tab
The website encountered an unexpected error. Try again later.
TypeError: Cannot access offset of type array in isset or empty in Drupal\Core\Extension\ModuleHandler->moduleExists() (line 267 of core/lib/Drupal/Core/Extension/ModuleHandler.php).
Drupal\hook_event_dispatcher\HookEventDispatcherModuleHandler->moduleExists(Array) (Line: 55)
Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager->alterDefinitions(Array) (Line: 344)
Drupal\Core\Plugin\DefaultPluginManager->findDefinitions() (Line: 216)
Drupal\Core\Plugin\DefaultPluginManager->getDefinitions() (Line: 412)
Drupal\jsonapi_extras\Form\JsonapiResourceConfigForm->buildOverridesField('nid', Object) (Line: 309)
Drupal\jsonapi_extras\Form\JsonapiResourceConfigForm->buildOverridesForm(Object, Object) (Line: 138)
Drupal\jsonapi_extras\Form\JsonapiResourceConfigForm->form(Array, Object) (Line: 108)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 559)
Drupal\Core\Form\FormBuilder->retrieveForm('jsonapi_resource_config_add_form', Object) (Line: 299)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::wrapControllerExecutionInRenderContext():121}() (Line: 638)
Drupal\Core\Render\Renderer::{closure:Drupal\Core\Render\Renderer::executeInRenderContext():638}()
Fiber->resume() (Line: 653)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::onController():96}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 54)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 30)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 118)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 92)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 71)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 54)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 753)
Drupal\Core\DrupalKernel->handle(Object) (Line: 34)
Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run() (Line: 32)
require('/Sites/wwguidenew/vendor/autoload_runtime.php') (Line: 22)
require_once('/Sites/wwguidenew/web/autoload_runtime.php') (Line: 13)
Proposed resolution
Filter out non strings
+ $modules = array_filter($definition_info['requiredModules'], 'is_string');
+ return !$modules ? [] : array_values($modules);
Probably caused by another module ruining the definitions?
Remaining tasks
Issue fork jsonapi_extras-3619857
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ptmkenny commentedWhich version of Drupal are you using?
Can you reproduce this from a clean install?
Obviously the overrides page generally works, or there would be tons of issues opened up about that...
Comment #3
johnzzonIt does not reproduce on a clean install. Tried with Drupal 11.4.4, PHP 8.4, jsonapi_extras 8.x-3.28, nothing else enabled.
What does reproduce it is any other module providing a
ResourceFieldEnhancerplugin via a PHP attribute . A throwaway module with a single enhancer extendingResourceFieldEnhancerBasegives same error. Root issue seems to be that thedependenciesis a reserved key on the plugin attributes.Enhancers in jsonapi_extras is safe,
getClassDependencies()excludes the plugin class's own provider.Filtering to strings stops the fatal but silently drops the declared module dependencies of every enhancer not provided by jsonapi_extras, since core has already thrown them away.
requiredModulesas suggested before is a good candidate.If you think this approach is good, I can create a patch. However, it'd need coordination with other modules declaring enhancers.
Comment #4
ptmkenny commentedWhat does reproduce it: any other module that provides a ResourceFieldEnhancer plugin via a PHP attribute. I dropped in a throwaway module with a single enhancer extending ResourceFieldEnhancerBase and got a byte for byte identical backtrace, same frames, same line numbers, same ModuleHandler.php line 267.@johnzzon Does it work if you use an annotation instead of an attribute?
Also, I assume you wrote your post with an AI agent; please edit it down to the relevant stuff and don't just post everything, because most of it is noise.
Comment #5
johnzzonYes, it does seem to work with an annotation.
Yes, an agent did help with the summary of the issue. English is not my native language, so it helps me. I did read through, validate and edit a bit, but I'm sorry if it was still lengthy. I have trimmed it down to the essentials.
Comment #6
ptmkenny commentedComment #7
ptmkenny commented@johnzzon Thank you for shortening it. There's nothing wrong with using agents, but they can really write a lot sometimes.
So there's a problem with attributes somewhere, that's very useful to know. I'll set this back to active as you have confirmed a real bug.
Comment #8
johnzzonYes, I agree! Apologies.
Great, we encountered this after upgrading to D11. On our project where we encountered this it was the module
geofieldthat uses attribute onGeofieldGeoJsonEnhancer.Comment #9
interlated commentedPossibly geofield caused the issue originally. Caused by a secondary module that isn't providing the correct data structure.
Comment #10
mikell commentedI can confirm that this error occurs when using jsonapi_extras in combination with geofield.
I'm on drupal 11.4.6, jsonapi_extras on 3.28.0, geofield on 10.3.4
Comment #11
ptmkenny commentedCan someone confirm / point to evidence that this is the fault of jsonapi_extras and not geofield? I just want to make sure this is in the right issue queue.
Comment #12
johnzzonI think the real issue is that
dependencieson the attribute is core-reserved on attribute-based plugin definitions. This must've come in D11? See\Drupal\Component\Plugin\Attribute\AttributeBase::$dependencies