Problem/Motivation
After upgrading to PHP 8.1, we get a deprecated warning when the Image style Uri is not set on template_preprocess_image_style.
%type: @message in %function (line %line of %file) @backtrace_string. | a:6:{s:5:"%type";s:19:"Deprecated function";s:8:"@message";O:25:"Drupal\Core\Render\Markup":1:{s:9:" * string";s:77:"pathinfo(): Passing null to parameter #1 ($path) of type string is deprecated";}s:9:"%function";s:45:"Drupal\image\Entity\ImageStyle->supportsUri()";s:5:"%file";s:78:"/mnt/www/html/myproject/docroot/core/modules/image/src/Entity/ImageStyle.php";s:5:"%line";i:385;s:17:"@backtrace_string";s:16143:"#0 /mnt/www/html/myproject/docroot/core/includes/bootstrap.inc(346): _drupal_error_handler_real(8192, 'pathinfo(): Pas...', '/mnt/www/html/d...', 385)
#1 [internal function]: _drupal_error_handler(8192, 'pathinfo(): Pas...', '/mnt/www/html/d...', 385)
#2 /mnt/www/html/myproject/docroot/core/modules/image/src/Entity/ImageStyle.php(385): pathinfo(NULL, 4)
#3 /mnt/www/html/myproject/docroot/core/modules/image/image.module(274): Drupal\image\Entity\ImageStyle->supportsUri(NULL)
#4 /mnt/www/html/myproject/docroot/core/lib/Drupal/Core/Theme/ThemeManager.php(287): template_preprocess_image_style(Array, 'image_style', Array)
#5 /mnt/www/html/myproject/docroot/core/lib/Drupal/Core/Render/Renderer.php(422): Drupal\Core\Theme\ThemeManager->render('image_style', Array)
#6 /mnt/www/html/myproject/docroot/core/lib/Drupal/Core/Render/Renderer.php(201): Drupal\Core\Render\Renderer->doRender(Array, false)
This seems because the URI is not defined on the variable URI when the method supportsUri is called, function template_preprocess_image_style.
https://git.drupalcode.org/project/drupal/-/blob/9600a0b13a4301c0071dad3...
....
if ($style->supportsUri($variables['uri'])) {
$variables['image']['#uri'] = $style->buildUrl($variables['uri']);
}
else {
...
Steps to reproduce
Try to generate an image style without URI (can be tried with a render array).
Proposed resolution
Check if the URI is set before calling supportURI, because the method expects a string, or change the param to string|null and verify there is the param is a string.
It is possible that this fix conflicts with issues:
- null in template_preprocess_image_style()
-
">Call to a member function transformDimensions() on null in template_preprocess
Issue fork drupal-3306131
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
eduardo morales albertiComment #4
eduardo morales albertiComment #5
eduardo morales albertiComment #6
maxilein commentedI'd test, but there is no patch...
Comment #7
eduardo morales alberti@mxilein you can use the diff of the merge request as patch https://git.drupalcode.org/project/drupal/-/merge_requests/2680/diffs.patch
Comment #9
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Thank you for working on this.
The MR should be updated to 9.5.x and a separate MR for 10.1.x
Tagging for tests to show this error.
Comment #10
robcarrThe MR (applied as a patch) worked for me.
Comment #11
hoporr commentedThere is a conflict with another open issue
"Call to a member function transformDimensions() on null in template_preprocess"
https://www.drupal.org/project/drupal/issues/2957368
Both issues change the same section of code. Since the other issue had more changes, and the fix for this issue here is just one line, I added that safety check into the other issue's patch (now in patch #50).