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

Command icon 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

interlated created an issue. See original summary.

ptmkenny’s picture

Status: Active » Postponed (maintainer needs more info)

Which 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...

johnzzon’s picture

It 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 ResourceFieldEnhancer plugin via a PHP attribute . A throwaway module with a single enhancer extending ResourceFieldEnhancerBase gives same error. Root issue seems to be that the dependencies is 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. requiredModules as 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.

ptmkenny’s picture

What 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.

johnzzon’s picture

Yes, 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.

ptmkenny’s picture

Title: Error loading the overrides form » Error loading the overrides form when using a ResourceFieldEnhancer with a PHP attribute
Version: 8.x-3.28 » 8.x-3.x-dev
Status: Postponed (maintainer needs more info) » Active
ptmkenny’s picture

@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.

johnzzon’s picture

Yes, I agree! Apologies.

Great, we encountered this after upgrading to D11. On our project where we encountered this it was the module geofield that uses attribute on GeofieldGeoJsonEnhancer.

interlated’s picture

Possibly geofield caused the issue originally. Caused by a secondary module that isn't providing the correct data structure.

mikell’s picture

I 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

ptmkenny’s picture

Can 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.

johnzzon’s picture

I think the real issue is that dependencies on the attribute is core-reserved on attribute-based plugin definitions. This must've come in D11? See \Drupal\Component\Plugin\Attribute\AttributeBase::$dependencies