Problem/Motivation

After updating Single Content Sync to 1.4.17 on Drupal 10.6.18, pages that invoke hook_entity_operation() can fail with an ArgumentCountError.

For example, visiting the Domain administration list results in:

ArgumentCountError: Too few arguments to function single_content_sync_entity_operation(), 1 passed and exactly 2 expected in single_content_sync_entity_operation() (line 82 of modules/contrib/single_content_sync/single_content_sync.module).

The stack trace shows Drupal invoking entity operation hooks with one argument:

Drupal\Core\Extension\ModuleHandler->invokeAll()
Drupal\Core\Entity\EntityListBuilder->getOperations()
Drupal\domain\DomainListBuilder->getOperations()

Steps to reproduce

  1. Install Drupal 10.6.18.
  2. Install or update Single Content Sync to 1.4.17.
  3. Visit an entity listing that calls EntityListBuilder::getOperations().
  4. An ArgumentCountError occurs when Drupal invokes single_content_sync_entity_operation().

The Domain administration entity listing is one page where the problem is reproducible.

Proposed resolution

In 1.4.17, single_content_sync_entity_operation() is declared as:

function single_content_sync_entity_operation(EntityInterface $entity, CacheableMetadata $cacheability) {

However, Drupal 10 invokes hook_entity_operation() with the entity as the single argument.

The second $cacheability argument is also not used by the function.

Changing the function back to the previous signature resolves the error:

function single_content_sync_entity_operation(EntityInterface $entity) {

The now-unused CacheableMetadata import can also be removed.

Patch/diff:

diff --git a/single_content_sync.module b/single_content_sync.module
--- a/single_content_sync.module
+++ b/single_content_sync.module
@@
 use Drupal\Core\Access\AccessResult;
-use Drupal\Core\Cache\CacheableMetadata;
 use Drupal\Core\Entity\ContentEntityTypeInterface;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Routing\RouteMatchInterface;
@@
-function single_content_sync_entity_operation(EntityInterface $entity, CacheableMetadata $cacheability) {
+function single_content_sync_entity_operation(EntityInterface $entity) {
   $operations = [];

   if (\Drupal::service('single_content_sync.helper')->access($entity)) {

After making this change and rebuilding caches, the affected entity listing loads normally.

Environment

  • Drupal core: 10.6.18
  • Single Content Sync: 1.4.17
  • PHP: 8.3
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

ljwilson created an issue. See original summary.

jpro’s picture

I'm seeing this issue, too.

peter pulsifer made their first commit to this issue’s fork.

peter pulsifer’s picture

I'm seeing this issue too, and have seen it in another module where CacheableMetadata was introduced. I think the best (simplest) soliution would be to change the function definition to
function single_content_sync_entity_operation(EntityInterface $entity, ?CacheableMetadata $cacheability=null) {

This should be standard procedure when adding that parameter.

nginex’s picture

Assigned: Unassigned » nginex

I'm working on it, thanks for reporting

  • nginex committed 99ec045b on 1.4.x
    Issue #3627999 Fix hook drupal 10 compatibility
    
nginex’s picture

Assigned: nginex » Unassigned
Status: Active » Fixed

Apply solution as siggested by Peter

Going to push it as 1.4.18 ASAP

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.

nginex’s picture

1.4.18 is now available
Thanks everyone involved

Status: Fixed » Closed (fixed)

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