FileExists class not available in Drupal 10.3, causes compatibility issue

Created on 10 June 2025, about 1 month ago

Problem/Motivation

The ScriptFileManager::save() method assumes the presence of the class \Drupal\Component\FileSystem\FileExists, which does not exist in Drupal < 10.3, leading to a fatal error.

This issue also occurs when updating the module from version 8.x-1.25 to 8.x-1.26, specifically during update hook hook_update_8129(), which regenerates the disabling script and invokes the save() method, triggering the error under the right conditions.

Additionally, the code redundantly saves the generated script file twice, using both the file_system and file.repository services:

$this->fileSystem->saveData($this->generatedScript, $this->absolutePath(), FileExists::Replace);
\Drupal::service('file.repository')
  ->writeData($this->generatedScript, $this->absolutePath(), FileSystemInterface::EXISTS_REPLACE);

Steps to reproduce

  • Install version 8.x-1.25 of the module on a site running Drupal < 10.3.
  • Set the module's settings, including the configuration to disable JavaScript files when consent isn't given.
  • Update the module to version 8.x-1.26.
  • Trigger update hook 8129.

Proposed resolution

  • Replace the usage of the non-existent FileExists::Replace with the available constant FileSystemInterface::EXISTS_REPLACE for Drupal < 10.3
  • Remove the double saving

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.26

Component

Code

Created by

🇮🇹Italy antonio.lepore Macerata

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024