Problem/Motivation
Hi,
When I updated my website from 9.5 to 10.2, I found myself unable to edit some contents, whether they're published or not.
I get the following error message :
The website encountered an unexpected error. Try again later.
TypeError: uasort(): Argument #1 ($array) must be of type array, null given in uasort() (line 65 of core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php).
Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getPluginId() (Line: 50)
Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getInstance() (Line: 101)
Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getSelectionHandler() (Line: 671)
Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem->getSettableOptions() (Line: 143)
Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase->getOptions() (Line: 34)
Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget->formElement() (Line: 448)
Drupal\Core\Field\WidgetBase->formSingleElement() (Line: 98)
Drupal\Core\Field\WidgetBase->form() (Line: 186)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm() (Line: 121)
Drupal\Core\Entity\ContentEntityForm->form() (Line: 127)
Drupal\node\NodeForm->form() (Line: 107)
Drupal\Core\Entity\EntityForm->buildForm()
call_user_func_array() (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult() (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
Drupal\Core\DrupalKernel->handle() (Line: 19)
Only some types of nodes have this problem, it seems it's those which can be created my any logged-in user, without special privileges, but I could be wrong.
These nodes have only a couple of text field, and a reference to commerce products, but other types of nodes with the same fields but that can only be created of edited by moderators work fine.
Comments
Comment #5
tabestan commentedHere's a patch that works with 10.2.x.
Comment #6
wanjee commentedI have the same error message in 10.2.6 when I try to add a field of type "reference" or "media" to a content type or paragraph (did not test other entity types).
Patch provided in #5 also fixes this issue.Patch lead to another issue in the same flow ( : "Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "selection_handler" for route "system.entity_autocomplete" must match "[^/]++" ("" given) to generate a corresponding URL. in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 209 of /var/www/html/docroot/core/lib/Drupal/Core/Routing/UrlGenerator.php)."
I think the root cause is related to this ticket: https://www.drupal.org/project/drupal/issues/2327883
Comment #7
pearls commentedTested. Cannot apply patch #5 (3419074-uasort-plugin-manager.patch)
Tested version: Drupal 10.3.2.
Comment #8
coaston commentedHI shenron_segamag,
I am experiencing the same issue - it was caused by uninstalling business rules which have been used as "dependent field" based on this guide here :dependent-field, so I had to install it back, however business rules are not D10 ready and are replaced with ECA.
For D10 it would be better to achieve the same with this module dependent_fields and this guide: guide
In my case for every content type where such "dependent" business rule entity reference is being used I am unable to edit/add once bussines rules module is not available. In content which does not have such rule everything works as expected. So looks like similar or the same issues to me.
Maybe it is different case, but at least it can help anyone else who tries to migrate from D9 to D10 and deleted all business rules but forgot to get rid of rules configured in views as entity reference.
Comment #10
shenron_segamag commentedHi @coaston,
Thank you, I had no idea business rules was a requirement to use dependent fields. I have already started to use ECA instead of it, but I will follow your advice to totally get rid of it.
Comment #11
mialdi98 commentedCreated a patch for version 10.3.0 , as attached #5 and the one that comes with a merge request didn't work.
Comment #12
mdranove commentedFor me patch in #11 fixes the exception in SelectionPluginManager, but then leads to the exception described in #6.
I think this patch ought to be a temporary solution. Believe this is isn't necessary in d11.
Comment #13
kumudbI am not able to reproduce this on Drupal 11.x.dev version there is no error occuring while creating or editing node type with entity reference fields.
Steps to Reproduce
1. Create a Content Type
.
2.Test Permissions:
3. Test Node Edit:
4.Check Field Configuration:
Comment #14
cilefen commentedComment #15
smustgrave commentedBumping 1 more time for steps before closing please.
Comment #16
mykola dolynskyiFaced similar (not exact) but with inline_entity_form
And I think this solves any current and my problem Argument #1 ($array) must be of type array, null given in uasort() (line 74 of core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php)