By kim.pepper on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
10.3.x
Introduced in version:
10.3.0
Issue links:
Description:
\Drupal\Core\File\FileSystemInterface replace behaviour constants deprecated and replaced with a \Drupal\Core\File\FileExists enum.
| Before | After |
|---|---|
FileSystemInterface::EXISTS_RENAME |
FileExists::Rename |
FileSystemInterface::EXISTS_REPLACE |
FileExists::Replace |
FileSystemInterface::EXISTS_ERROR |
FileExists::Error |
If you have a method that accepts an int argument of one of the old constants you can use \Drupal\Core\File\FileExists::fromLegacyInt() to convert the value to the new enum. For example:
Old code
public function myMethod($arg1, $arg2, $replace = FileSystemInterface::EXISTS_RENAME) {
// Your code...
}
Code with deprecation
public function myMethod($arg1, $arg2, /* FileExists */$replace = FileExists::Rename) {
if (!$fileExists instanceof FileExists) {
// @phpstan-ignore-next-line
$fileExists = FileExists::fromLegacyInt($fileExists, __METHOD__);
}
// Your code...
}
New code
Once all your dependents have had a chance to update.
public function myMethod($arg1, $arg2, FileExists $replace = FileExists::Rename) {
// Your code...
}
Impacts:
Module developers