Argument #1 ($array) must be of type array when editing node

Created on 4 February 2024, 10 months ago
Updated 4 March 2024, 9 months ago

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.

๐Ÿ› Bug report
Status

Active

Version

11.0 ๐Ÿ”ฅ

Component
Entity referenceย  โ†’

Last updated 3 days ago

No maintainer
Created by

๐Ÿ‡ซ๐Ÿ‡ทFrance shenron_segamag

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @shenron_segamag
  • First commit to issue fork.
  • Pipeline finished with Failed
    9 months ago
    Total: 162s
    #110468
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance tabestan Sargentville, Maine

    Here's a patch that works with 10.2.x.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wanjee

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

  • Tested. Cannot apply patch #5 (3419074-uasort-plugin-manager.patch)
    Tested version: Drupal 10.3.2.

  • ๐Ÿ‡ธ๐Ÿ‡ฐSlovakia coaston

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

  • First commit to issue fork.
  • Pipeline finished with Failed
    about 2 months ago
    Total: 4404s
    #296657
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance shenron_segamag

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

  • Created a patch for version 10.3.0 , as attached #5 and the one that comes with a merge request didn't work.

  • For 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.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia KumudB Ahmedabad

    I 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

    • Add fields that reference other entities, such as Commerce Products or other content types.
    • Allow any logged-in user to create/edit these nodes

    .

    2.Test Permissions:

    • Ensure permissions are assigned such that non-moderator roles can interact with these fields.

    3. Test Node Edit:

    • Create a node type.
    • Attempt to edit the node as a user with minimal privileges.

    4.Check Field Configuration:

    • Review the entity reference fieldโ€™s storage and widget settings.
    • Ensure the selection handler is correctly set and aligns with the referenced entity type.
Production build 0.71.5 2024