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

CommentFileSizeAuthor
#2 3381787.patch570 bytessthomen

Issue fork viewfield-3381787

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

khaldoon_masud created an issue. See original summary.

sthomen’s picture

StatusFileSize
new570 bytes

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

hockey2112’s picture

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

maxilein’s picture

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

Just for the sake of finding this important issue faster via google:
That problem was solved for me with this patch too (Maybe in a combination with https://www.drupal.org/project/viewfield/issues/3267240).


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)
jannakha’s picture

Status: Active » Reviewed & tested by the community

patch #2 works, please release the module!

hockey2112’s picture

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

ilfelice’s picture

Howdy,

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

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

fonant’s picture

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

thomaswalther’s picture

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

4kant’s picture

#2 works for me in 10.2.2

chris burge’s picture

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.

alfthecat’s picture

Patch #2 and the patch found here: https://www.drupal.org/project/viewfield/issues/3267240 solved the issue for me.

caspervoogt’s picture

#2 patch worked for me

xurizaemon’s picture

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

xurizaemon’s picture

Issue tags: +DrupalSouth 2024
itamair’s picture

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

danflanagan8 made their first commit to this issue’s fork.

danflanagan8’s picture

Status: Reviewed & tested by the community » Needs work

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.

danflanagan8’s picture

Status: Needs work » Needs review

Tests are green again.

jannakha’s picture

Status: Needs review » Reviewed & tested by the community

thanks for the update.
tested and it works.

please release a new version!

danflanagan8’s picture

Status: Reviewed & tested by the community » Fixed

  • danflanagan8 committed b67fb578 on 8.x-3.x
    Issue #3381787 by danflanagan8, sthomen, khaldoon_masud, hockey2112,...
danflanagan8’s picture

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

Status: Fixed » Closed (fixed)

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

defcon0’s picture

@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

danflanagan8’s picture

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

See #3449950: Cannot select display of view in default value - possible regression

dd 85’s picture

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

danflanagan8’s picture

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

dd 85’s picture

Why does #24 say that this has been fixed and the status is Closed (fixed)?

danflanagan8’s picture

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

danflanagan8’s picture

A more successful fix is being attempted in the related issue: #3449950: Cannot select display of view in default value - possible regression