Error: Call to a member function transformDimensions() on null in template_preprocess_image_style() (line 303 of /core/modules/image/image.module) #0 /core/lib/Drupal/Core/Theme/ThemeManager.php(287):

Comments

Amsteri created an issue. See original summary.

amsteri’s picture

Status: Active » Needs review
StatusFileSize
new3.51 KB
scuba_fly’s picture

StatusFileSize
new773 bytes
+++ b/core/modules/image/image.module
@@ -294,39 +294,47 @@ function image_style_options($include_empty = TRUE) {
+  } else {

Nice work! Makes sense.
Instead of adding another else here, we could do an early return.

This would make the code a little less complex.
Also this would make the patch a lot smaller:

diff --git a/core/modules/image/image.module b/core/modules/image/image.module
index 4c0e8cca99..3e1601d9c6 100644
--- a/core/modules/image/image.module
+++ b/core/modules/image/image.module
@@ -294,6 +294,14 @@ function image_style_options($include_empty = TRUE) {
 function template_preprocess_image_style(&$variables) {
   $style = ImageStyle::load($variables['style_name']);
 
+  if (!$style) {
+    \Drupal::logger('image')->warning('Image style (@style) missing for @image. Please add the missing style under /admin/config/media/image-styles.', [
+      '@style' => $variables["style_name"],
+      '@image' => $variables['uri'],
+    ]);
+    return;
+  }
+
   // Determine the dimensions of the styled image.
   $dimensions = [
     'width' => $variables['width'],
scuba_fly’s picture

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

robcarr’s picture

I encountered a problem with the Simple Login module (#3166927)- the patch at #3 sorted this issue out.

andrewsuth’s picture

I can also confirm that patch #3 works as expected.

chaithanya.m’s picture

Status: Needs review » Reviewed & tested by the community

I have applied the patch #3 and it works fine after applying the patch.

scuba_fly’s picture

After reconsideration this does not significantly impacts ( only one ) subsystem. Removing the tag.
Thanks for @lauriii for pointing this out on slack.

jsutta’s picture

I can confirm patch #3 works.

quietone’s picture

Version: 8.9.x-dev » 9.2.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests, +Needs issue summary update

This looks like a nice fix but I am pretty sure this will need a test. And let's use the issue summary template and explain the proposed resolution.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

sbasile’s picture

Is this still an issue for 8.9.15? Trying to determine if I should use #3.

dhirendra.mishra’s picture

StatusFileSize
new773 bytes

Re-rolled this against 9.3.x from #3

vikashsoni’s picture

StatusFileSize
new9.11 KB
new224 KB

The patch is working fine after the patch i am able to access site for ref sharing screenshot

bnjmnm’s picture

This may be a duplicate of #2957368: Call to a member function transformDimensions() on null in template_preprocess and #3145187: Default image + No preview = fatal error?

If this isn't a duplicate, adding "Needs steps to reproduce", just to ensure that is taken into account when "needs issue summary update" is addressed.

Similarly, #16 Does not provide any new information, just what was already provided in the issue summary but as a screenshot instead of code snippet.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dqd’s picture

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.