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

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

anthonyroundtree created an issue. See original summary.

george square360’s picture

Status: Active » Needs review
StatusFileSize
new3.52 KB

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

anthonyroundtree’s picture

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

  1. applied patch
  2. instead of updating viewsreference, I updated entityqueue from 1.10 to 1.12 (the issue first appeared when entityqueue was updated to 1.12. My original solution was to rollback to 1.10 which didn't work either).
  3. removed the composer.lock file
  4. ran composer install

I can confirm the patch works, but I'm not sure if it worked without the update to entityqueue as well?

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

scott_euser’s picture

Title: ArgumentCountError in DEV causing page error » Argument Count Error in Drupal Core prior to 11.4 missing contextual links helper
Issue summary: View changes
scott_euser’s picture

  • scott_euser committed a769d298 on 8.x-2.x
    fix: #3613134 Argument Count Error in Drupal Core prior to 11.4 missing...
scott_euser’s picture

Status: Needs review » Fixed

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

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.