Problem/Motivation
With PHP 8.1 passing null to non-nullable argument will generate a deprecation notice.
Uploading an SVG can cause a deprecation notice as $type is defined when calling image_type_to_extension in GDToolkit.php.
$type is not defined as SVG is not a supported type.
Steps to reproduce
Install Drupal 9.x with PHP 8.1.
Add a an image field to an entity that supports svg extensions.
Upload an SVG.
See deprecation message:
Deprecated function: image_type_to_extension(): Passing null to parameter #1 ($image_type) of type int is deprecated in Drupal\system\Plugin\ImageToolkit\GDToolkit->load() (line 202 of core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php).
Proposed resolution
Check the $type is not null before calling image_type_to_extension.
For example.
$function = $this->getType() ? 'imagecreatefrom' . image_type_to_extension($this->getType(), FALSE) : NULL;
if ($function && function_exists($function) && $resource = $function($this->getSource()))Remaining tasks
Create an MR.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3338962
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 #3
cilefen commented9.5.x is the bug fix branch.
Comment #4
tcrawford commentedThanks. I will re-roll this against 9.5.x-dev.
Comment #5
ranjit1032002Created a patch for the issue mentioned, please review.
Thank You.
Comment #6
smustgrave commentedThis issue was started in an MR and should remain there.
Thank you @tcrawford for steps to reproduce. This will need a test case showing the issue.
Comment #8
sakthi_dev commented@smustgrave added the patch from #5 to MR.
Comment #9
mondrakeThis issue is a bit obscure to me... the GD toolkit does not support SVG images, since GD does not (and likely will never) support vectorial graphic formats. Normally unsupported file formats would fail much earlier than where you are proposing to fix, i.e. in file extension validations, where the file extension of the file to-be-uploaded is matched against the file extensions that an image toolkit supports. I'm not sure how you can have an
? Maybe with contrib?
Comment #11
tcrawford commented@mondrake You are right. The issue only occurs for me in projects using the drupal/rokka module, which uses its own RokkaToolkit that extends the GDToolkit. Rokka supports the svg extension, but there is no related type and so we see the type error.
I guess we need to get have the Rokka Toolkit modified to override the load() method also and check that getType() is set.
I am closing this issue as 'cannot reproduce' as it only occurs in combination with the RokkaToolkit.
Comment #12
tcrawford commented