Comments

samvel’s picture

Assigned: Unassigned » samvel
samvel’s picture

Issue summary: View changes

add related issue

samvel’s picture

Issue summary: View changes

append related issue

samvel’s picture

Status: Active » Needs review
Issue tags: +CodeSprintUA
StatusFileSize
new16.52 KB

attached

samvel’s picture

Issue summary: View changes

append related issue

Status: Needs review » Needs work

The last submitted patch, replace-theme-with-render-2009580-2.patch, failed testing.

samvel’s picture

Status: Needs work » Needs review
StatusFileSize
new60.78 KB

attached new one

Status: Needs review » Needs work

The last submitted patch, replace-theme-with-render-2009580-4.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new60.78 KB

re-roll

Status: Needs review » Needs work

The last submitted patch, replace-theme-with-render-2009580-4_.patch, failed testing.

thedavidmeister’s picture

Assigned: samvel » Unassigned

feel free to re-assign if you're still working on this @Samvel

hussainweb’s picture

StatusFileSize
new60.14 KB

I was trying to reroll this patch when I came across a few issues about which I am not entirely sure.

In block.admin.inc and HelpController.php, render arrays are replaced with calls to drupal_add_css. Such as:

    $output = array(
      '#attached' => array(
        'css' => array(drupal_get_path('module', 'help') . '/css/help.module.css'),
      ),
      '#markup' => '<h2>' . t('Help topics') . '</h2><p>' . t('Help is available on the following items:') . '</p>' . $this->helpLinksAsList(),
    );

This is replaced with:

    // Add CSS.
    drupal_add_css(drupal_get_path('module', 'help') . '/css/help.css');
    $output = '<h2>' . t('Help topics') . '</h2><p>' . t('Help is available on the following items:') . '</p>' . $this->helpLinksAsList();

I was in an impression that we are moving towards render arrays for everything. Please clarify.

Another issue I faced was in core/modules/node/node.admin.inc. The patch introduced a change in node_multiple_delete_confirm_submit() but it seems that this function (and many others) are completely removed. I checked the documentation and they seem to be removed.

Lastly, I don't see why this patch removes core/modules/system/lib/Drupal/system/Tests/InstallerTest.php and modifies scripts in core/scripts/generate-d7-content.sh and core/scripts/generate-d6-content.sh.

But in good faith, I have just gone ahead and rerolled the patch. Please set the issue to 'needs review' if you think the above issues are not problems.

pplantinga’s picture

Status: Needs work » Needs review
StatusFileSize
new9.03 KB

Agreed on those issues. Also, many changes, while they could be good ones, were unrelated to this issue.

Here's a new patch. Just a quick question, do we care about theme() calls in tests? This patch only covers image.admin.inc and image.file.inc, not any test files.

Status: Needs review » Needs work

The last submitted patch, replace-theme-image-module-2009580-10.patch, failed testing.

pplantinga’s picture

Status: Needs work » Needs review
StatusFileSize
new8.99 KB

Argh, decided I'd add an "alt" tag to preview images, didn't know that tests depended on not having it. Whoever reviews this should look at questions I had in #10.

jenlampton’s picture

Status: Needs review » Needs work

Yeah, we should remove the theme calls in tests as well. Do you want to take a stab at adding those in?

pplantinga’s picture

Status: Needs work » Postponed
pplantinga’s picture

StatusFileSize
new19.08 KB

Once the aforementioned issue is in, then this patch should do it.

c4rl’s picture

How is #2030243: Remove theme_file_upload_help() from the theme system not accommodated by, and thus duplicate of this present issue?

pplantinga’s picture

The name for the issue was not as clear as it could have been, since i came across it while working on this issue. I've just renamed it. It looks like a resolution is near for the issue, so it shouldn't matter that much either way.

Basically that issue is about a FAPI conflict in a file.module theme function, which appears in more places than just the image module. I felt it deserved a separate issue.

pplantinga’s picture

StatusFileSize
new18.72 KB

Re-roll patch, again assuming that #2030243: Remove theme_file_upload_help() from the theme system gets in.

eric_a’s picture

@@ -47,7 +48,8 @@ function image_style_form($form, &$form_state, $style) {
   $form['preview'] = array(
     '#type' => 'item',
     '#title' => t('Preview'),
-    '#markup' => theme('image_style_preview', array('style' => $style)),
+    '#theme' => 'image_style_preview',
+    '#style' => $style,
   );

Mixing up elements like this is a bad idea. It just so happens that there (currently) is no conflict here between the properties of the two elements, but we should just separate these properly. Especially if we want to do #2035977: Introduce #type elements for base theme hooks in image.module.
Type item by default does not declare #theme and does declare #theme_wrappers, so we should try something like this:

   $form['preview'] = array(
     '#type' => 'item',
     '#title' => t('Preview'),
-    '#markup' => theme('image_style_preview', array('style' => $style)),
+    'image_style_preview' => array(
+      '#theme' => 'image_style_preview',
+      '#style' => $style,
+    ),
   );
eric_a’s picture

It might not even work still. In many cases it will just work: the rendered children of the item will be concatenated with an empty #markup property string.
Safest would be to just populate the #markup property, with a #pre_render. EDIT2: #pre_render would perhaps be out of scope for these straight conversions I guess. Just a direct drupal_render() then. This would mean that the current patch is already taking an out of scope approach here.

thedavidmeister’s picture

#19 just looks to me like a workaround for a bug - that you can't use #theme_wrappers => array('form_element') with 'file_upload_help'. We could move this issue forward using that approach, but I don't see any harm in cleaning up the namespace conflict with the FAPI first.

eric_a’s picture

You can use any #theme_wrapper you like. And combine it with any fitting #theme. The point is that you must not merge elements of different types into one level. That can always lead to conflicts. There is no way to solve that.

thedavidmeister’s picture

The point is that you must not merge elements of different types into one level. That can always lead to conflicts. There is no way to solve that.

This is true. At this point though, I don't think 'file_upload_help' is a #type.

eric_a’s picture

Yeah, I should have said:
Different elements cannot just be merged into one element on one level.
Every single element has its own properties (explicit or implicit as type defaults), be it #input, #markup, #theme, #theme_wrappers, #description. Merging elements will lead to conflicts.
So they must live as a siblings or a children. Of course, when early rendering into a string every type can be stuffed into #markup.

eric_a’s picture

How would you convert this example?

$form['preview'] = array(
   '#type' => 'item',
   '#title' => t('Preview'),
   '#markup' => theme('image_style_preview', array('style' => $style)) . theme('more_link', array('url' => $url, 'title' => $title)),
);

I can come up with three options:

$form['preview'] = array(
   '#type' => 'item',
   '#title' => t('Preview'),
   '#markup' => drupal_render($image_style_preview) . drupal_render($more_link),
);
$form['preview'] = array(
   '#type' => 'item',
   '#title' => t('Preview'),
   '#pre_render' => array('please_populate_my_type_item_markup_property'),
);
$form['preview'] = array(
   '#type' => 'item',
   '#title' => t('Preview'),
   'image_style_preview' => $image_style_preview,
   'more_link' => $more_link,
);

In many ways the third seems best. But for alterable structures moving the contents of #markup to newly invented children is API breakage.
Even when there is only one theme function used to build #markup, I think you should still not try and merge it into another element. It's messy and many a time it won't even be possible.
Note that if there was a #theme property involved (explicit or implicit as type default) the children would not be rendered by drupal_render() itself. They would have to be taken care of by the theme function.

thedavidmeister’s picture

But for alterable structures moving the contents of #markup to newly invented children is API breakage.

True dat. Given that we're past the 1st of July, I think option one for the conversion would be the most palatable.

It also follows the instructions in the parent issue:

Don't try to do anything new/fancy like returning the renderable array instead of rendering it where theme() was, despite this probably being "better" in many cases it will also incur quite a bit of extra testing overhead. We're trying to minimise the scope of this issue. Don't change the name/structure of any existing variables or try to add/remove/merge any existing functions. Touch nothing but the lamp (@see Aladdin). If the patch does change anything else, it will need manual testing and therefore slow/stall what should be relatively simple tasks. @thedavidmeister, who wrote this rule, is aware of the irony/hypocrisy in that the patches he submitted (before writing this rule) all refactored things slightly when they probably shouldn't have :P

thedavidmeister’s picture

Status: Postponed » Needs work
pplantinga’s picture

Status: Needs work » Needs review
StatusFileSize
new18.96 KB

Updated patch.

Status: Needs review » Needs work

The last submitted patch, replace-theme-image-module-2009580-28.patch, failed testing.

pplantinga’s picture

Status: Needs work » Needs review
StatusFileSize
new18.96 KB

d'oh.

pplantinga’s picture

Looks like test bot likes it. I forgot to mention that I addressed issue raised in #19.

sbudker1’s picture

Issue tags: +Needs reroll

Looks like this needs a reroll!

hussainweb’s picture

Issue tags: -Needs reroll
StatusFileSize
new16.83 KB

Rerolled...

thedavidmeister’s picture

Status: Needs review » Needs work
-  $output .= '<a href="' . $original_url . '">' . theme('image', array('uri' => $original_path, 'alt' => t('Sample original image'), 'title' => '', 'attributes' => $original_attributes)) . '</a>';
+  $output .= l($image, $original_url, array('html' => TRUE));

Are we 100% sure this doesn't change the behaviour of this theme function? url() processes urls passed to l(), which may be good/bad/neutral here, but are we ok with this change? it looks out of scope for a straight conversion of the theme() function.

+  $preview = array(
+    '#theme' => 'image',
+    '#uri' => $preview_url,
+    '#alt' => t('Sample modified image'),
+    '#title' => '',
+    '#attributes' => $preview_attributes,
+  );

Any reason this render array's variable name doesn't match the naming convention established in the parent issue?

-  $output .= check_plain($style->label()) . ' (' . l(t('view actual size'), file_create_url($preview_file) . '?' . time()) . ')';
+  $output .= check_plain($style->label()) . ' (' . l(t('view actual size'), $preview_url ) . ')';

This looks out of scope for this conversion. Although it does look worthy of it's own issue.

-  $output .= '<a href="' . file_create_url($preview_file) . '?' . time() . '">' . theme('image', array('uri' => $preview_url, 'alt' => t('Sample modified image'), 'title' => '', 'attributes' => $preview_attributes)) . '</a>';
+  $output .= l($preview, $preview_url, array('html' => TRUE));

Again, conversion to l() looks out of scope here.

-  return theme('image_resize_summary', array('data' => $data)) . ' ' . ($data['upscale'] ? '(' . t('upscaling allowed') . ')' : '');
+  $image_resize_summary = array(
+    '#theme' => 'image_resize_summary',
+    '#data' => $variables['data'],
+  );
+  return drupal_render($image_resize_summary) . ($variables['data']['upscale'] ? ' (' . t('upscaling allowed') . ')' : '');

This changes the trailing whitespace in the output in the case that $variables['data']['upscale'] is falsey, this change is out of scope for this conversion.

pplantinga’s picture

Any reason this render array's variable name doesn't match the naming convention established in the parent issue?

Just a better variable name, more descriptive, more consistent and all that. I've changed it to $image in the latest patch though.

conversion to l() looks out of scope here

I've verified that the output is identical... does that help? Converting theme() to l() is indirectly changing theme() to drupal_render() since l() calls drupal_render(). That's my angle, at any rate. I've attached two patches, with and without that change.

The rest should be fixed as well.

pplantinga’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, replace-theme-image-module-no-l-2009580-35.patch, failed testing.

thedavidmeister’s picture

I've verified that the output is identical... does that help? Converting theme() to l() is indirectly changing theme() to drupal_render() since l() calls drupal_render(). That's my angle, at any rate. I've attached two patches, with and without that change.

I personally think it's probably a good thing, I'm just suspicious that there may have been a reason for that link to be manually concatenated rather than using l() "once upon a time" and that reasoning may or may not still hold true. I wanted to direct people's attention towards it simply to invite discussion - I'm ok with including it if everyone else is.

pplantinga’s picture

Status: Needs work » Needs review
siccababes’s picture

It needed a re-roll

siccababes’s picture

StatusFileSize
new15.4 KB
thedavidmeister’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to me. If there are any further changes, can we please get an interdiff on each update? It's long enough to justify them.

claudiu.cristea’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/image/image.field.incundefined
@@ -433,12 +437,12 @@ function theme_image_formatter($variables) {
-  if (isset($item['entity']) && empty($item['uri'])) {
-    $image['#uri'] = $item['entity']->getFileUri();
-  }
-  else {
+  if (!empty($item['uri'])) {
     $image['#uri'] = $item['uri'];
   }
+  elseif (isset($item['entity'])) {
+    $image['#uri'] = $item['entity']->getFileUri();
+  }

So this change makes it possible for $image['#uri'] to not be set. Why are we changing the logic here (in a conversion issue)

pplantinga’s picture

Status: Needs work » Needs review
StatusFileSize
new720 bytes
new14.87 KB

Re-rolled and updated with changes in #44

drupalmonkey’s picture

Assigned: Unassigned » drupalmonkey
drupalmonkey’s picture

Assigned: drupalmonkey » Unassigned
Status: Needs review » Reviewed & tested by the community

Images are loading correctly in the admin area and on a node. Ran the tests for image module locally with patch and came back green. Setting RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 3f97e8c and pushed to 8.x. Thanks!

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

Anonymous’s picture

Issue summary: View changes

append @ to related tasks