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
- Install Drupal 10.6.18.
- Install or update Single Content Sync to 1.4.17.
- Visit an entity listing that calls
EntityListBuilder::getOperations(). - An
ArgumentCountErroroccurs when Drupal invokessingle_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
Issue fork single_content_sync-3627999
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
jpro commentedI'm seeing this issue, too.
Comment #4
peter pulsifer commentedI'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.
Comment #5
nginex commentedI'm working on it, thanks for reporting
Comment #7
nginex commentedApply solution as siggested by Peter
Going to push it as 1.4.18 ASAP
Comment #9
nginex commented1.4.18 is now available
Thanks everyone involved