Content reference field reuse is broken

Created on 25 January 2024, 10 months ago
Updated 10 February 2024, 9 months ago

Problem/Motivation

Originally issue was spotted while creating reference field on content for two variation types within Drupal Commerce with domain module and it's relatives installed (including domain_menus). New field was created correctly, but when I tried to re-use it in another variation - I received fatal error with following trace:

TypeError: uasort(): Argument #1 ($array) must be of type array, null given in uasort() (line 64 of /app/web/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php).
#0 /app/web/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php(64): uasort(NULL, Array)
#1 /app/web/core/modules/field/field.module(414): Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getPluginId('node', 'domain_menus')
#2 [internal function]: field_field_config_create(Object(Drupal\field\Entity\FieldConfig))
#3 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(409): call_user_func_array(Object(Closure), Array)
#4 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(388): Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object(Closure), 'field')
#5 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(416): Drupal\Core\Extension\ModuleHandler->invokeAllWith('field_config_cr...', Object(Closure))
#6 /app/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(341): Drupal\Core\Extension\ModuleHandler->invokeAll('field_config_cr...', Array)
#7 /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(239): Drupal\Core\Config\Entity\ConfigEntityStorage->invokeHook('create', Object(Drupal\field\Entity\FieldConfig))
#8 /app/web/core/modules/field_ui/src/Form/FieldStorageReuseForm.php(259): Drupal\Core\Entity\EntityStorageBase->create(Array)
#9 [internal function]: Drupal\field_ui\Form\FieldStorageReuseForm->reuseCallback(Array, Object(Drupal\Core\Form\FormState))
#10 /app/web/core/lib/Drupal/Core/Form/FormSubmitter.php(129): call_user_func_array(Array, Array)
#11 /app/web/core/lib/Drupal/Core/Form/FormSubmitter.php(67): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#12 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(597): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#13 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm('field_ui_field_...', Array, Object(Drupal\Core\Form\FormState))
#14 /app/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\field_ui\Form\FieldStorageReuseForm), Object(Drupal\Core\Form\FormState))
#15 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#16 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#17 /app/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#18 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#19 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#20 /app/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#21 /app/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#22 /app/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /app/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /app/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /app/vendor/asm89/stack-cors/src/Cors.php(53): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /app/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Asm89\Stack\Cors->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /app/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /app/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 /app/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#32 /app/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#33 /app/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#34 {main}

Stepped with debugger into the last spot and found that uasort() receives null because info related to "domain_manus:node" plugin is hidden under "default" key of array, but function expect it to be retrievable from array by plugin_id (domain_menus come as plugin_id to this function). See debugger.jpg in attachments for details. When I changed DomainMenusSelection's annotation parameter "group" to "domain_menus" re-use was completed successfully.

Steps to reproduce

Install domain_menus module and it's dependencies on clean Drupal 10.2.2. Create 3 new content types, create reference field on new_type_1 content type inside new_type_3. Try to reuse that field in new_type_2 -> receive fatal error.

Proposed resolution

Change DomainMenusSelection plugin's annotation parameter "group" value from "default" to "domain_menus"

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

3.5

Component

Code

Created by

πŸ‡§πŸ‡ΎBelarus aylis

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024