Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Part of #2006152: [meta] Don't call theme() directly anywhere outside drupal_render().
Resolution depends on #2026319: Mis-named variables in picture_theme(). Tests on this issue will continue to fail until that issue's patch is committed.
How To Test:
- Enable picture module.
- Go to Config, media and add picture mapping
- Assign three different image styles to the picture mapping.
- Edit image field display on article content type.
- Change formatter from image to picture.
- Create an article and upload an image.
- Save the article.
- Resize the browser to see all three image styles.
Comment | File | Size | Author |
---|---|---|---|
#85 | 2009662-wip.patch | 1.75 KB | lokapujya |
#75 | interdiff.txt | 5.09 KB | jessebeach |
#75 | picture-formatter-tests-2009662-0.patch | 9.05 KB | jessebeach |
#63 | interdiff.txt | 1.27 KB | Eric_A |
#63 | drupal8.theme-system.2009662-63-test-only.patch | 4.78 KB | Eric_A |
Comments
Comment #1
InternetDevels CreditAttribution: InternetDevels commentedWe are working today with this issue during Code Sprint UA.
Comment #2
InternetDevels CreditAttribution: InternetDevels commentedPatch attached.
Comment #3
podarok#2 looks good
RTBC
Comment #4
alexpottAre you sure? Seems like we have both path and uri...
Comment #5
thedavidmeister CreditAttribution: thedavidmeister commentedl() already calls drupal_render() on its content, no need to do it here.
@alexpott is right, this is not the issue to be making these changes. Please open a separate issue if you want to see these changed.
Please use https://drupal.org/node/2006152#comment-7487406 rather than https://drupal.org/node/2006152#comment-7487410 if possible.
Comment #6
sbudker1 CreditAttribution: sbudker1 commentedComment #7
jenlampton#2: picture-replace_theme_with_drupal_render-2009662-1.patch queued for re-testing.
Comment #8
jenlamptonexpecting this needs a reroll, tagging.
Comment #10
pwieck CreditAttribution: pwieck commentedBringing this back up to speed with reroll.
Comment #11
pwieck CreditAttribution: pwieck commentedReroll to current head and removed out of scope changes. Fixed everything in #5 EXCEPT:
I did not change this part because I did not understand...sorry
Please use https://drupal.org/node/2006152#comment-7487406 rather than https://drupal.org/node/2006152#comment-7487410 if possible.
Comment #12
thedavidmeister CreditAttribution: thedavidmeister commented@pwieck: Not sure if you saw what I said in IRC but:
Comment #13
pwieck CreditAttribution: pwieck commented#11 failing due to moving out of scope changes to this issue - Undefined index: uri and Undefined index: dimensions in picture.module
Comment #14
jenlamptonI'm getting some weird results here... I started by trying to work on the patch in #11, and I couldn't get pictures to render at all, so i returned to the patch in #2 but realised that never even passed tests, so I started over.
It appears that when we change
to
everything goes all snafu with the image URI. Instead of getting
...sites/default/files/styles/large/public/field/image/IMG_1123.jpg?itok=E4nZ42Bn
like it should, calling drupal_render gets a URI of...sites/default/files/styles/large/public?itok=yQEzZDg9
The only difference I can see between $picture and $item is that $item had a key of entity. I tried setting a #entity key on the picture - just as a longshot - but it doesn't seem to have any effect.
Comment #15
jenlamptonHere's a patch if anyone else wants to play with this. Please note, I've commented out some lines in here that you can use for testing the theme -> drupal_render issues, but they will need to be removed eventually.
Comment #16
jlbellidoChanged status for run tests
Comment #18
jlbellidoRerolled #15
Comment #19
jlbellidoRemoved some debug code from #18 and run test
Comment #21
pwieck CreditAttribution: pwieck commentedRemember, this should keep failing until #13 is completed. This was out of scope for this issues and was moved. See also #4 and #5. It was my understanding that #2 test passed the first time but someone re-tested and then failed due to needing a re-roll.
Comment #22
pplantinga CreditAttribution: pplantinga commentedLike @pwieck said, this is stuck on #2026319: Mis-named variables in picture_theme().
Once that goes through, this slightly modified patch should cover it:
Comment #23
pplantinga CreditAttribution: pplantinga commented#2026319: Mis-named variables in picture_theme() is in.
Here's the re-rolled patch.
Comment #23.0
pplantinga CreditAttribution: pplantinga commentedUpdated issue summary.
Comment #23.1
adamcowboy CreditAttribution: adamcowboy commentedAdding how to test.
Comment #24
adamcowboy CreditAttribution: adamcowboy commentedIt works! Also, I added a How To Test section.
Comment #25
alexpottThere seems to be considerable overlap with #1898442: responsive_image.module - Convert theme_ functions to Twig... personally I think the issues should be merged - will leave it to the twig team to decide what to do. Afaics #1898442: responsive_image.module - Convert theme_ functions to Twig converts more to twig...
Comment #26
alexpottSetting to "needs review" so people know there's a decision to make :)
Comment #27
pplantinga CreditAttribution: pplantinga commentedI think this needs to happen regardless of what happens in #1898442: responsive_image.module - Convert theme_ functions to Twig.
All instances of theme() need to be removed somehow, and conflicts are easily resolved. Trying to figure out which conversions to do in which issue is only going to waste time, in my opinion.
Comment #28
thedavidmeister CreditAttribution: thedavidmeister commentedHey, I just linked to this issue from #1898442: responsive_image.module - Convert theme_ functions to Twig.
If this is RTBC I think we should get it in. Not only are the conflicts easily resolved but it's the same person who's rolled the most recent patches on both issues so I don't think there's any harm in getting this RTBC cleanup in before the other issue that is still CNW.
@pplantinga, would you be happy to be in charge of re-rolling the Twig patch if this lands now?
Comment #29
pplantinga CreditAttribution: pplantinga commentedHappy to do it.
Comment #30
alexpottCommitted e21ba43 and pushed to 8.x. Thanks!
Comment #31
Eric_A CreditAttribution: Eric_A commentedI just saw this in the commit log. I'm assuming that being able to leave out the alt attribute here is as valid an option for
theme_picture_formatter()
as fortheme_image_formatter()
so I guess this will need the same repair work as is being done now fortheme_image_formatter()
in #2010126: Replace theme() with drupal_render() in image module for theme_image_formatter().Comment #33
Eric_A CreditAttribution: Eric_A commentedHere's a patch that fixes the regression introduced here the same way as in #50 from #2010126: Replace theme() with drupal_render() in image module for theme_image_formatter() but without test assertions. Does someone familiar with (the output from)
theme_picture_formatter()
andtheme_picture()
feels like copying and adapting the alt parts fromcore/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
into methodstestPictureFormatterTheme()
andtestPictureTheme()
in a new filecore/modules/picture/lib/Drupal/picture/Tests/PictureThemeFunctionTest.php
?Comment #34
Eric_A CreditAttribution: Eric_A commentedMissed one in
theme_image_formatter()
.Comment #35
pplantinga CreditAttribution: pplantinga commentedLooks good to me. Not sure that the new tests necessarily need to be done here.
Comment #36
effulgentsia CreditAttribution: effulgentsia commentedSince #34 is a straight up bug fix, and according to #33, a regression caused by the earlier refactor here, then we do need tests here to prevent a similar regression happening next time this code is refactored.
Comment #37
porchlight CreditAttribution: porchlight commentedworking on tests.
Comment #38
porchlight CreditAttribution: porchlight commentedThe tests should pass, but they don't. The fix is still including an alt attribute to the picture element whether its null or not. The title attribute is included in both cases as well. The title attribute if null shouldn't be there anyways, since it's not required by html standards.
Here is prior to #34
and with fix from #34
Comment #40
star-szrI worked on the tests with @travis-echidna. I suspect getting a passing patch is not a Novice task at this point, removing tag. @Eric_A if you are able to pick this up again that would be very helpful.
We suspected this might be part of the problem with the empty title attribute always being added:
Comment #41
Eric_A CreditAttribution: Eric_A commentedIndeed.
Reverted part of the code in #34, because while (NULL) values should pass through to other theme hooks, once the actual rendering takes place the NULL values are there to be ignored when building the attributes.
Fixed test: we're re-using part of the element and therefor
render()
instead ofdrupal_render()
, just like inImageThemeFunctionTest
.I reviewed the test and there is still some work to do:
A test for
theme_picture_formatter()
is needed.Compared to the test method names in
ImageThemeFunctionTest
this is a change in the wrong direction I think. "Function" is not correct anymore when the function is converted to a template. Better to stay consistent and usetestPictureTheme
. (We might change the class names too at some point, but not here.)Comment #43
Eric_A CreditAttribution: Eric_A commentedI forgot to attach the test-only patch. Note the difference in fails.
Comment #45
Eric_A CreditAttribution: Eric_A commentedGotcha.
Comment #46
Eric_A CreditAttribution: Eric_A commented@travis-echidna, can you take it from here?
Comment #47
star-szrWe did have the alt removal right at one point :) thanks for spotting that @Eric_A.
Comment #48
c4rl CreditAttribution: c4rl commentedI had a look at the test and it seems that rendered element is returning:
While the expected result is
So it appears the expected result assumes a missing alt attribute while the rendered version simply has an empty alt attribute.
Comment #49
c4rl CreditAttribution: c4rl commentedWait, this seems to be fine, right? The test-only patch should fail and the normal patch should come out fine? So nothing is the matter?
Marking this as needs review, not needs work.
Comment #50
c4rl CreditAttribution: c4rl commentedRemoving `needs tests` tag.
Comment #51
Eric_A CreditAttribution: Eric_A commentedStill needs a test for
theme_picture_formatter()
. See #41 and #33.Comment #52
c4rl CreditAttribution: c4rl commentedDoh! Missed that. Thanks, @Eric_A.
Comment #53
jeanfei CreditAttribution: jeanfei commentedComment #54
jeanfei CreditAttribution: jeanfei commentedI've apply #45 patch and added a new test for theme_picture_formatter().
Comment #55
pplantinga CreditAttribution: pplantinga commentedLooks good to me!
Comment #56
Eric_A CreditAttribution: Eric_A commentedKudos to jeanfei for looking into this and adding assertions. If everything is well with both the alt changes for theme_picture_formatter() and the new assertions then in a test-only patch the alt === NULL related ones will fail and the bonus assertions will pass.
Comment #57
Eric_A CreditAttribution: Eric_A commented#56: drupal8.theme-system.2009662-54-test-only.patch queued for re-testing.
Comment #58
Eric_A CreditAttribution: Eric_A commentedThe test-only patch did not fail on "theme_picture_formatter() correctly renders with a NULL value for the alt option.".
I took another look at the code and concluded that the change I made tries to fix the scenario with breakpoints involved. So we need to add an assertion with breakpoints involved regarding
theme_image_formatter()theme_picture_formatter()
.@jeanfei, do you feel like finishing up? (If not, then it's best to unassign.)
I also spotted a documentation issue.
This is testing
theme_picture_formatter()
, nottheme_picture()
.Comment #59
jeanfei CreditAttribution: jeanfei commentedComment #60
Eric_A CreditAttribution: Eric_A commentedThe test coverage may be just good enough for now for our purposes, when taking into account that for the breakpoints case the current implementation code delegates to theme_picture() which has coverage. Looking into that now.
Comment #61
Eric_A CreditAttribution: Eric_A commentedThe input in #38 and #48 by @travis-echidna and @c4rl is the kind that will help this issue further.
What is the expected markup for a suitable breakpoint (
$variables['breakpoints'] as $breakpoint_name => $multipliers
;$multipliers as $multiplier => $image_style
)?I'd be happy to add the test coverage for that in
testPictureFormatterThemeFunction()
.We need that because the fact of the matter is that the current incarnation of the added
testPictureFormatterThemeFunction()
is not testing the fix intheme_picture_formatter()
and thus will not prevent us from regressing again. From this point of view I would suggest to postpone other refactorings of the picture module (like #1898442: responsive_image.module - Convert theme_ functions to Twig) on this issue.Comment #62
Eric_A CreditAttribution: Eric_A commentedI'm taking this back, because the regression here should not be another issues problem. We'll just have to reroll here if other refactorings get in first.
Comment #63
Eric_A CreditAttribution: Eric_A commentedDoc fix and more precise assertion message as per #58. Needs review to let the bot test again.
Comment #65
Eric_A CreditAttribution: Eric_A commented#63: drupal8.theme-system.2009662-63.patch queued for re-testing.
Comment #65.0
Eric_A CreditAttribution: Eric_A commentedEditing How To Test section.
Comment #66
joelpittetThis bit is redundant.
same here.
This sounds a bit to heavy and duplicated to be of much use. Also it's advocating calling theme() directly which we are trying to avoid.
The tests look nice. Good work @Eric_A
Comment #67
Eric_A CreditAttribution: Eric_A commentedThe "redundant" part is a pattern for performance used by core in more places.
I don't think there is a way right now to get around the duplicating of the docs. It's already in core in more places that use these attributes this way.
The most important thing right now is for somebody to respond to what I said in #61.
I've added #2010126: Replace theme() with drupal_render() in image module for theme_image_formatter() to the related issue. It has all the reasons for why everything is done exactly this way. (RTBC'd by @pplantinga and committed by @alexpott).
Comment #68
joelpittet@Eric_A the performance bit is the isset(), and isset is used to help shortcut out of the condition quicker. That was what it was by default, no need to also check if the key exists because the isset() does just that.
No idea on the breakpoint question.
The big alt comment is hitting people over the head with information they should already know and doesn't directly explain why or what is happening in the code directly beneath it. Better off finding one good place, likely in a docblock someplace to add that comment once and be done with it.
Comment #69
mariacha1 CreditAttribution: mariacha1 commented@Eric_A
Not sure I'm 100% understanding the question you're asking about breakpoints, but here's what I've found...
in theme_picture_formatter looks like $variables['breakpoints'] is an array in the structure like this:
While the output created looks like this:
Sorry if this doesn't help, maybe it will be a nudge for someone more experienced. :)
Comment #70
Eric_A CreditAttribution: Eric_A commentedThanks for the info, @mariacha1.
Note that things have changed now because of #2042773: Change #items within a theme_field() render array from an *array* to the same $items *object* used throughout the rest of the formatter pipeline. The diff there makes me think that the bug fixing here may have gotten easier; now may be the time to move the assertions that are not related to this specific bug into their own issue.
Comment #71
jessebeach CreditAttribution: jessebeach commentedThe previous title no longer applies.
theme()
is no longer invoked in the Picture module.Comment #72
Eric_A CreditAttribution: Eric_A commented@jessebeach, are you saying that the regression does not exist anymore, possibly as a side effect of #2042773: Change #items within a theme_field() render array from an *array* to the same $items *object* used throughout the rest of the formatter pipeline? If so, please share some information here. For now I'm changing the title to what it should have been since #31. The point of quickly reopening this issue in #31/#33 was to fix a regression introduced by the conversion. Which was the same regression that had just happened in #2010126: Replace theme() with drupal_render() in image module for theme_image_formatter(). If it was just about docs and adding test coverage it would not have made much sense to keep this issue open.
Comment #73
jessebeach CreditAttribution: jessebeach commentedSorry, I hadn't realized this issue concerned fixing a regression. I was going off the title and the fact that
grep -r -E 'theme\(' ./core/modules/picture
wasn't turning up any theme function invocations. I might suggest in the future that we open a followup bug for a regression rather than tacking on to a committed issue. But that's not really important now, since you largely have the regression addressed here. I'll give your patch a review. Thank you for staying on top of this.Comment #74
jessebeach CreditAttribution: jessebeach commentedComment #75
jessebeach CreditAttribution: jessebeach commentedHere's an article that expounds on the performance pattern that Eric_A mentions in #67: http://www.zomeoff.com/php-fast-way-to-determine-a-key-elements-existanc...
tl:dr
$arr = array('myKey' => NULL); isset($arr['myKey']); //returns false even though the key is technically set.
Here's the HTML for a picture element:
Personally, I would expect the alt attrs not to print if they're empty.
PictureFieldDisplayTest
tests that the HTML for the formatter display is rendering properly.I'm not 100% certain what exactly the regression is. Eric_A, is it just that the tests weren't passing?
In any case, I've rerolled the patch so that the additional tests pass. I used
ImageThemeFunctionTest
as a guide.Comment #76
joelpittetThis is not necessary, the isset() is the performance part, the || array_key_exists() does the same thing again if the first condition is true, making it slower.
Comment #77
star-szrMaybe this is a silly idea or I'm missing something (it would be an API change) but what about using FALSE instead of NULL to omit the alt attribute? Seems more intentional and easier to test for.
Comment #78
joelpittetnm #76, the array_key_exist is checking for NULL so value can be omitted. @Cottser's right. Thanks for the link @Cottser http://www.zomeoff.com/php-fast-way-to-determine-a-key-elements-existanc...
The isset() is for performance like I said, though the array_key_exists will allow NULL values through the condition.
Comment #79
star-szrThe link was from @jessebeach :)
Comment #80
joelpittetAh, sorry @jessebeach didn't see that link earlier.
Comment #81
joelpittet@Eric_A want to give #75 a go to see if it solve the regression you are mentioning?
Comment #82
RainbowArraySo I hate to rain on the parade of all the work that has been done on this issue, but looks as if this is about outputting an alt attribute on the picture element, but there shouldn't be an alt attribute on the picture element. The alt attribute goes on the img element inside of the picture element.
The specification for the picture element has changed in the last couple months, so it's possible alt was on picture in the past, but that's no longer the case.
Here's the current spec: http://picture.responsiveimages.org
Comment #83
RainbowArrayI misread this patch. Took a closer look, and I can see now that part of the tests relate to having alt on the picture element (which has now been removed in #2211831: Removal of alt attribute from [picture] tag). The other tests to relate to the img element within the picture element, which are still valid.
So this patch needs to be rerolled, also because of #2124377: Rename "Picture" module to "Responsive Image" module.
Once that rerolling is done, then I guess we can test the use of FALSE instead of NULL. I do wonder if NULL was used in #2010126: Replace theme() with drupal_render() in image module for theme_image_formatter(), why we'd use FALSE here instead. It seems confusing to use two different methods. If FALSE is faster, that's great, but then we should change the image module to the FALSE method too, after this.
Comment #84
star-szrThere was a commit here in July 2013 and this issue is still open. This is a great example of why re-opening issues after commit is so confusing (even moreso to newcomers to the issue queue) and opening a follow-up issue is 99.9% of the time the best thing to do (hint: Dreditor gives you a clone issue button).
I agree with @mdrummond that if we use FALSE to not show the empty
alt=""
we should be consistent about it, and I would suggest that API change could be handled in a separate issue to keep focus here and close this issue out as soon as possible.Comment #85
lokapujyaWorking on rerolling the test. I think that means that we add to this existing test.
Comment #87
panche CreditAttribution: panche commentedI'm working on the reroll to join the patch #85 with #75
Comment #90
panche CreditAttribution: panche commentedI talked with @lokapujya via IRC and he told me "..it should have been opened as a new issue, instead of trying to fix the regresssion in the already applied patch."
I talked personally with @yesct and she proposed opening a new issue (agreeing with @lokapujya), so we are opening #2425493: Allow picture to not have a 'tag' attribute and add tests for responsive_image module. so we can apply the patches to reponsive_image core module.
The patches that we are moving from here are #75 and #85 so they can be re-rolled.
I'm rolling back to the original state when this issue was a normal task in #30.
Comment #91
panche CreditAttribution: panche commented