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).
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3381787.patch | 570 bytes | sthomen |
Issue fork viewfield-3381787
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
Comment #2
sthomen commentedI 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.
Comment #3
hockey2112 commentedThanks for this, I ran into this issue today. The patch works. Can this be rolled into a new release ASAP?
Comment #4
maxilein commentedThere 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).
Comment #5
jannakha commentedpatch #2 works, please release the module!
Comment #6
hockey2112 commentedRan into this again today on a different website. Can this be rolled into a new release of the module?
Comment #7
ilfelice commentedHowdy,
FWIW, patch #2 works here too. Drupal 10.1.5 here.
Would be really nice to have a release with this patch. ;)
Comment #8
fonant commentedPatch #2 works to fix the problem for me, too.
Comment #9
thomaswalther commentedPatch #2 works to fix the problem for me, too. Using Drupal 10.2.1
Comment #10
4kant commented#2 works for me in 10.2.2
Comment #11
chris burge commentedI 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.
Comment #12
alfthecat commentedPatch #2 and the patch found here: https://www.drupal.org/project/viewfield/issues/3267240 solved the issue for me.
Comment #13
caspervoogt commented#2 patch worked for me
Comment #14
xurizaemonLooks a good candidate for upcoming 3.0 release? Plenty of RTBC+1s here.
Comment #15
xurizaemonComment #16
itamair commented#2 patch worked for me also. Let's deploy it in a new module release?
Comment #19
danflanagan8I 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.
Comment #20
danflanagan8Tests are green again.
Comment #21
jannakha commentedthanks for the update.
tested and it works.
please release a new version!
Comment #22
danflanagan8Comment #24
danflanagan8I just tagged 8.x-3.0-beta8, which includes this fix. Thanks, all!
Comment #26
defcon0 commented@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
Comment #27
danflanagan8@Defcon0, I see the change to
ViewfieldItem::defaultFieldSettingsin beta8. It's more likely that the fix just doesn't work.See #3449950: Cannot select display of view in default value - possible regression
Comment #28
dd 85 commentedI'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.
Comment #29
danflanagan8@DD 85, please see the test results reported in #19. The patch in #2 is not sufficient.
Comment #30
dd 85 commentedWhy does #24 say that this has been fixed and the status is Closed (fixed)?
Comment #31
danflanagan8@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.
Comment #32
danflanagan8A more successful fix is being attempted in the related issue: #3449950: Cannot select display of view in default value - possible regression