follow up #2009580: Replace theme() with drupal_render() in image module

Need replace theme('image', $variables) with drupal_render() in theme_image_style()

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alphawebgroup’s picture

Issue tags: -CodeSprintUA

starting in #CodeSprintUA

alphawebgroup’s picture

Assigned: Unassigned » alphawebgroup
Issue tags: +CodeSprintUA

tagging

alphawebgroup’s picture

Issue tags: +CodeSprintUA
FileSize
1.22 KB
andypost’s picture

+++ b/core/modules/image/image.moduleundefined
@@ -1002,15 +1002,20 @@ function theme_image_style($variables) {
+    // Width and height
...
+    // Add in the image style name as an HTML class
...
+    ),
+    // Determine the URL for the styled image

Add . at the end of each comment

alphawebgroup’s picture

FileSize
1.23 KB
andypost’s picture

Status: Active » Needs review
podarok’s picture

Status: Needs review » Reviewed & tested by the community

#5 looks good

Samvel’s picture

May be i not understand, i see that now alt and title missing in image.

alphawebgroup’s picture

Status: Reviewed & tested by the community » Needs work

yep, Samvel is right...
needs work..

alphawebgroup’s picture

Im preparing the new one as suggested by Samvel and Andypost. Will place new patch soon.

alphawebgroup’s picture

Status: Needs work » Needs review
FileSize
1.62 KB

Status: Needs review » Needs work

The last submitted patch, 2010134-11.patch, failed testing.

andypost’s picture

4 tests are broken.

+++ b/core/modules/image/image.moduleundefined
@@ -999,18 +999,33 @@ function theme_image_style($variables) {
-
+  ¶

trailing whitespace

+++ b/core/modules/image/image.moduleundefined
@@ -999,18 +999,33 @@ function theme_image_style($variables) {
+  // Finding all available theme registry variables for image style.
+  $hooks = theme_get_registry(FALSE);

this could be too expensive!!! (memory)

Samvel’s picture

There are drupal_static. Can you advise, how get specified (only one) theme registry?

thedavidmeister’s picture

Assigned: alphawebgroup » Unassigned

Feel free to re-assign this @alweb if you're still working on this.

Anonymous’s picture

Assigned: Unassigned »

ok taking this one for today

Anonymous’s picture

Assigned: » Unassigned

As in the #13 comment that this function $hooks = theme_get_registry(FALSE); is too expensive.I also have the same question as in #14.Need help in this.for now I unassign this and continue after suggestions.if anyone interested then feel free to work on it.

pplantinga’s picture

Status: Needs work » Needs review
FileSize
1.19 KB

Here's a new patch.

siccababes’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -CodeSprintUA

I tested this patch by creating an article and uploading an image. Everything went fine. Changing to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/image/image.moduleundefined
@@ -900,15 +900,25 @@ function theme_image_style($variables) {
-  $variables['width'] = $dimensions['width'];
-  $variables['height'] = $dimensions['height'];
-
   // Add in the image style name as an HTML class.
   $variables['attributes']['class'][] = 'image-style-' . drupal_html_class($variables['style_name']);
 
-  // Determine the URL for the styled image.
-  $variables['uri'] = image_style_url($variables['style_name'], $variables['uri']);
-  return theme('image', $variables);
+  $image = array(
+    '#theme' => 'image',
+    '#width' => $dimensions['width'],
+    '#height' => $dimensions['height'],
+    '#attributes' => $variables['attributes'],
+    '#uri' => image_style_url($variables['style_name'], $variables['uri']),
+  );
+
+  if (isset($variables['alt'])) {
+    $image['#alt'] = $variables['alt'];
+  }
+  if (isset($variables['title'])) {
+    $image['#title'] = $variables['title'];
+  }
+

Why are we making so many changes here? We seem to be fixing things as well... if so we need tests and to change the title...

This issue should just convert the theme call to drupal_render and a follow up should be filed if there is a bug.

pplantinga’s picture

Status: Needs work » Needs review

There's no bug, it just takes many lines of code in this instance to change theme() to drupal_render() because every variable going to drupal_render() has to be declared explicitly.

$image is the array going to drupal_render(), and every variable previously being passed to theme() through the $variables array needs to be transferred explicitly to $image.

jenlampton’s picture

Status: Needs review » Needs work

@pplantinga can you just reroll one more time? remove these lines:

+
+  if (isset($variables['alt'])) {
+    $image['#alt'] = $variables['alt'];
+  }
+  if (isset($variables['title'])) {
+    $image['#title'] = $variables['title'];
+  }
+
alexpott’s picture

Status: Needs work » Reviewed & tested by the community

@jenlampton actually reading @pplantinga comment makes me realise I'm wrong and he is right.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

It's the problem with arrays of doom :) ... $variables sucks...

Committed e5b7fb4 and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.