Problem/Motivation
Trying to update a site, but when running composer install, views reference and entityqueue updated. I thought the issue may have been entityqueue, but the page that is broken is the home page. All other pages seem to work fine.
The website encountered an unexpected error. Try again later.
ArgumentCountError: Too few arguments to function Drupal\viewsreference\Plugin\Field\FieldFormatter\ViewsReferenceFieldFormatter::__construct(), 7 passed in /var/www/html/web/core/lib/Drupal/Core/Field/FormatterBase.php on line 80 and exactly 8 expected in Drupal\viewsreference\Plugin\Field\FieldFormatter\ViewsReferenceFieldFormatter->__construct() (line 29 of modules/contrib/viewsreference/src/Plugin/Field/FieldFormatter/ViewsReferenceFieldFormatter.php).
Steps to reproduce
Use Drupal Core 11.3 or lower where the contextual links helper service does not yet exist
Comments
Comment #2
george square360 commentedRoot cause: commit ae78ed7 (from #3612695) added a ContextualLinksHelper constructor parameter to ViewsReferenceFieldFormatter without adding a matching create() override. FormatterBase::create() passes the standard 7 arguments, so every render of a viewsreference field throws the ArgumentCountError above — current 2.x HEAD is broken for all sites tracking 2.x-dev.
There is a second problem behind it: \Drupal\views\ContextualLinksHelper only exists in core 11.4+, while this module declares core_version_requirement: ^10 || ^11 || ^12. Even with a correct create() override, sites on 10.x or 11.0–11.3 would still fatal, because neither the class nor its autowired service exists on those cores.
The attached patch fixes both:
- adds the create() override, injecting the helper via $container->has(ContextualLinksHelper::class) so it resolves to NULL on cores that predate the service;
- makes the constructor parameter nullable (?ContextualLinksHelper $contextualLinksHelper = NULL);
- guards both call sites (?-> in ViewsReferenceFieldFormatter, \Drupal::hasService() in ViewsReferenceLazyFieldFormatter) so contextual links are simply not added on older cores — the same behavior those sites had before ae78ed7.
Workaround until this lands, for anyone hitting the WSOD: pin the previous commit in composer.json — "drupal/viewsreference": "2.x-dev#49b2bc1398a8a272e2364b6ca04fc25645742959".
Comment #3
anthonyroundtree commentedI forgot to mention that I was running drupal 11.2.14. Thanks for that explanation because that really helped.
I messed up and instead of locking viewsreference as stated, I did the following steps using the patch as mentioned and it worked:
I can confirm the patch works, but I'm not sure if it worked without the update to entityqueue as well?
Comment #6
scott_euser commentedComment #7
scott_euser commentedComment #9
scott_euser commentedThanks both! I had to update the test coverage to be <=11.3 + 10.x compatible to be able to add test coverage for this hence the wider set of changes.