Getting PHP errors when setting default value

Created on 18 August 2023, about 1 year ago
Updated 3 June 2024, 5 months ago

Problem/Motivation

Getting PHP errors when setting default value for the field.

Steps to reproduce

1. Create a viewfield
2. In the field setting, check "Set default value" checkbox
3. Select any view from the "view" dropdown
4. The Display dropdown will be empty with two below messages in the drupal log.

Deprecated function: str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getInstance() (line 45 of /var/www/docroot/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php)

TypeError: uasort(): Argument #1 ($array) must be of type array, null given in uasort() (line 65 of /var/www/docroot/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php).

๐Ÿ› Bug report
Status

Fixed

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States khaldoon_masud

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

Merge Requests

Comments & Activities

  • Issue created by @khaldoon_masud
  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland sthomen

    I ran into this as well on Drupal 10.1, it seems that the validation of the field somehow fouls up.

    In this validation, SelectionPluginManager->getSelectionHandler() is called , and the second time the result of $field_definition->getSetting('hander') is null which causes the error with uasort in getInstance().

    I patched this by setting the 'handler' key in ViewFieldItem::defaultStorageSettings(), it is probably the wrong thing to but will fix the crash for those in dire need.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States hockey2112

    Thanks for this, I ran into this issue today. The patch works. Can this be rolled into a new release ASAP?

  • ๐Ÿ‡ฆ๐Ÿ‡นAustria maxilein

    There is a patch already. It works (D10.1 php 8.1)

    Just for the sake of finding this important issue faster via google:

    
    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: 97)
    Drupal\Core\Entity\Plugin\Validation\Constraint\ValidReferenceConstraintValidator->validate() (Line: 202)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateConstraints() (Line: 154)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode() (Line: 106)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validate() (Line: 93)
    Drupal\Core\TypedData\Validation\RecursiveValidator->validate() (Line: 132)
    Drupal\Core\TypedData\TypedData->validate() (Line: 307)
    Drupal\Core\Field\FieldItemList->defaultValuesFormValidate() (Line: 241)
    Drupal\field_ui\Form\FieldConfigEditForm->validateForm()
    call_user_func_array() (Line: 82)
    Drupal\Core\Form\FormValidator->executeValidateHandlers() (Line: 275)
    Drupal\Core\Form\FormValidator->doValidateForm() (Line: 118)
    Drupal\Core\Form\FormValidator->validateForm() (Line: 593)
    Drupal\Core\Form\FormBuilder->processForm() (Line: 325)
    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: 592)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 182)
    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: 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: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
    Drupal\Core\DrupalKernel->handle() (Line: 19)
    
  • Status changed to RTBC about 1 year ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia jannakha Brisbane!

    patch #2 works, please release the module!

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States hockey2112

    Ran into this again today on a different website. Can this be rolled into a new release of the module?

  • ๐Ÿ‡ฏ๐Ÿ‡ตJapan ilfelice

    Howdy,

    FWIW, patch #2 works here too. Drupal 10.1.5 here.

    Would be really nice to have a release with this patch. ;)

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom fonant

    Patch #2 works to fix the problem for me, too.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany thomaswalther Rhein-Main Area

    Patch #2 works to fix the problem for me, too.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany 4kant

    #2 works for me in 10.2.2

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States Chris Burge

    I can confirm that patch #2 addresses the issue. The behavior is reproducible when trying to add a new View field to a bundle.

    +1 for cutting a release.

  • ๐Ÿ‡น๐Ÿ‡ญThailand AlfTheCat

    Patch #2 and the patch found here: https://www.drupal.org/project/viewfield/issues/3267240 ๐Ÿ› Undefined array key "items_to_display" RTBC solved the issue for me.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States caspervoogt

    #2 patch worked for me

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand xurizaemon ลŒtepoti, Aotearoa ๐Ÿ

    Looks a good candidate for upcoming 3.0 release? Plenty of RTBC+1s here.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand xurizaemon ลŒtepoti, Aotearoa ๐Ÿ
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly itamair

    #2 patch worked for me also. Let's deploy it in a new module release?

  • First commit to issue fork.
  • Status changed to Needs work 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States danflanagan8 St. Louis, US

    I turned the patch into an MR, but the tests are failing because of schema issues:

    > Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for field.storage.node.field_view_test with the following errors: field.storage.node.field_view_test:settings.handler missing schema

    I'd like to fix that before merging.

  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States danflanagan8 St. Louis, US

    Tests are green again.

  • Status changed to RTBC 6 months ago
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia jannakha Brisbane!

    thanks for the update.
    tested and it works.

    please release a new version!

  • Pipeline finished with Skipped
    6 months ago
    #167446
  • Status changed to Fixed 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States danflanagan8 St. Louis, US
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States danflanagan8 St. Louis, US

    I just tagged 8.x-3.0-beta8 โ†’ , which includes this fix. Thanks, all!

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • @danflanagan8

    The release doesn't contain the fix even though in the git repo it is. Strange. Please check the ZIP on

    https://www.drupal.org/project/viewfield/releases/8.x-3.0-beta8 โ†’

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States danflanagan8 St. Louis, US

    @Defcon0, I see the change to ViewfieldItem::defaultFieldSettings in beta8. It's more likely that the fix just doesn't work.

    See ๐Ÿ› Cannot select display of view in default value - possible regression Active

  • ๐Ÿ‡ท๐Ÿ‡บRussia DD 85

    I'm working on creating a new website. And today, for the first time, I downloaded and installed the Viewfield module for this site.
    As described above, I encountered two errors:
    Deprecated function: str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getInstance() (line 45 of \core\lib\Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager.php)
    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).

    I found that there is no patch in the release of viewfield 8.x-3.0-beta 8 https://www.drupal.org/project/viewfield/issues/3381787#comment-15199519 ๐Ÿ› Getting PHP errors when setting default value Fixed
    The viewfield 8.x-3.x-dev 8 May 2024 development release does not have this patch either.

    I applied this patch manually by adding a line
    'handler' => 'default:view',
    and it helped me.
    The fix is working, but it has not yet been applied to any release version.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States danflanagan8 St. Louis, US

    @DD 85, please see the test results reported in #19. The patch in #2 is not sufficient.

  • ๐Ÿ‡ท๐Ÿ‡บRussia DD 85

    Why does #24 ๐Ÿ› Getting PHP errors when setting default value Fixed say that this has been fixed and the status is Closed (fixed)?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States danflanagan8 St. Louis, US

    @DD 85, it's because I turned the patch into an MR, made an update such that the tests pass, got an RTBC from someone, and then merged the MR.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States danflanagan8 St. Louis, US

    A more successful fix is being attempted in the related issue: ๐Ÿ› Cannot select display of view in default value - possible regression Active

Production build 0.71.5 2024