I've noticed that image styles seems to dislike numeric names like "940", although names like "1440_900" work. The description says: "The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-)."
I've also tried clearing the cache and so on. The image generated were used with colorbox and inserted through the image field module on my portfolio (http://jonathanmh.com). Changing the name to "fill_page" made the module generate the images in the right size immediately. (I watched the folder through ftp)
It's not the image that should be shown inside the colorbox that isn't generated but the one displayed in the post.
I think this is a bug, even though I'm very new to drupal (7) and considering it's PHP it looks a little like a typecasting error.
I talked to nbb on IRC and he came up with the following:
module: core image, version 7.7, file: image.module, function image_style_options line #683 -$options = array_merge($options, drupal_map_assoc(array_keys($styles))); +$options += drupal_map_assoc(array_keys($styles));
Comment | File | Size | Author |
---|---|---|---|
#25 | drupal-image_style_failure-1262591-25.patch | 1.71 KB | jmarkel |
#22 | drupal-image_style_failure-1262591-22.patch | 1.75 KB | jmarkel |
#20 | drupal-image_style_failure-1262591-20.patch | 1.73 KB | jmarkel |
#15 | image_style_numeric_test.patch | 1.04 KB | marcingy |
#15 | image_style_numeric_full.patch | 1.72 KB | marcingy |
Comments
Comment #1
joachim CreditAttribution: joachim commentedReassigning to core.
Comment #2
jmarkel CreditAttribution: jmarkel commentedLooking into this.
What I've found so far is that for an image style with a numeric name (as should be allowed - the number should be treated as a string in this context) the image_style name that's serialized to the database in table "field_config_instance" for an image_style named "100" is "0" instead.
I haven't tracked this down to its root yet, but I suspect that "100" is somewhere being treated as a numeric value instead of as a string.
Comment #3
bleen CreditAttribution: bleen commentedThis needs to be fixed in D8 first and then backported
Comment #4
jmarkel CreditAttribution: jmarkel commentedHah! Found it!
The problem seems to be that neither array_keys() nor array_merge() preserve the data types of the array keys, so an associative key of '100' is being coerced into an int - but it starts out, and ought to remain, a string.
I haven't written any new tests for it - not really sure how, and it seems a daunting task - the setup requires creating a numerically named image style, a new image field, a node-based entity containing the image field, and setting one of the entity's views to display the image using the new (numerical-string-named) image style.
Anyway, attaching the patch ...
Comment #5
bleen CreditAttribution: bleen commentedThanks for the patch ...
If "adding" the two arrays (instead of array_merge) preserves the keys then can't you remove this?
Comments should be full sentences including capitalization.
Adding tests is really not too hard and it makes a huge difference in moving your patches along in the process ... I'm happy to walk you through it in IRC #drupal (bleen)
-13 days to next Drupal core point release.
Comment #6
marcingy CreditAttribution: marcingy commentedSurely this change can be simplified to just
This will result in drupal_map_assoc casting to a string.
Comment #7
marcingy CreditAttribution: marcingy commentedOk my idea abvove won't work and there seems to be no way around the problem directly in php,
Comment #8
jmarkel CreditAttribution: jmarkel commentedYes, you're right, @bleen18 - after a re-look I saw that there was no need to replace the array_keys() call.
I'll look for you on irc for hints on writing tests...
Comment #9
jmarkel CreditAttribution: jmarkel commentedThink I figured out the testing - at least sufficient for this purpose. Here's a patch with test code included.
Comment #10
pingers CreditAttribution: pingers commentedRe-roll minus evil tabs :)
Comment #11
jmarkel CreditAttribution: jmarkel commentedThanks, @pingers. Yeah - I was just fixing that - tabs instead of spaces rears its ugly head :-(
Comment #12
bleen CreditAttribution: bleen commentedMost of this is code styling (... I highly recommend you install Dreditor as it will help point out the white space issues when you are looking at a patch on D.O.) But the last comment below could use some more opinions...
white space
needs a space after "for" and a space after each ";" and a space before and after "<="
white space
white space
white space
white space
white space
white space
white space
white space
white space
two spaces before the "{"
white space
white space
I think it would be much more practical to create a new function called "randomNumericString" or perhaps to just use $str = (string)rand(x,y); in your test.
Anyone else want to chime in on this one?
-14 days to next Drupal core point release.
Comment #13
marcingy CreditAttribution: marcingy commentedI don't believe there is any need to make changes to public static function randomName you can simply call rand() - http://php.net/manual/en/function.rand.php
Test style can also be pretty much left intact instead I would be something like this covert the existing test style to helper function
And then in the exist testStyle function do
Comment #14
marcingy CreditAttribution: marcingy commentedI don't believe there is any need to make changes to public static function randomName you can simply call rand() - http://php.net/manual/en/function.rand.php
Test style can also be pretty much left intact instead I would be something like this covert the existing test style to helper function
And then in the exist testStyle function do
Comment #15
marcingy CreditAttribution: marcingy commentedThe test approach above doesn't work. This test makes sure that a numeric style appears in the option list rather than being a value of 0. First patch is test only second patch is test plus fix.
Comment #16
bleen CreditAttribution: bleen commentedThis looks great!
Thanks @jmarkel & @marcingy
RTBC
Comment #17
jmarkel CreditAttribution: jmarkel commented@marcingy, I don't think your test exercises the functionality that is being fixed. The problem was not that the image style name did not appear in the list of available styles - it DID appear. The problem was that a style with a numeric name was not being used even when selected, because array_merge() was changing its array key value from a string type to an int typ. Because it became a numeric index in an array that was otherwise associative, the index became '0' instead of the int equivalent of the numeric style name. My test runs through the entire testStyle suite to make sure that the numeric style name is not breaking somewhere else in a similar way.
Comment #18
bleen CreditAttribution: bleen commentedI think this line here tests the functionality you are referring to. By asserting that the array key is returned correctly we are asserting that the root cause of the problem (the array merge mangling the keys) is no longer a problem. Once that root cause is tested then we can rely on the other tests that ensure that styles apply correctly. Make sense?
If so, you can put this back to RTBC. If not, why?
-14 days to next Drupal core point release.
Comment #19
jmarkel CreditAttribution: jmarkel commentedOkay, thanks @marcingy and @bleen - I see it now.
There is, however a change still to be made in that the test description is incorrect (and there's a typo in it) - it should be something like
"Test to make sure that an image style with a numeric name is applied to image fields correctly."
I can re-roll in the morning unless marcingy wants to do it before then.
Comment #20
jmarkel CreditAttribution: jmarkel commentedOkay - re-rolled with new comment for the new test.
Comment #21
bleen CreditAttribution: bleen commentedHow about "Test creating an image style with a numeric name and ensuring it can be applied to an image."
Comment #22
jmarkel CreditAttribution: jmarkel commentedAs requested...
Comment #23
bleen CreditAttribution: bleen commentedSold!! Looks good.
Comment #24
catchThanks. Committed/pushed to 8.x, moving to 7.x for backport.
Comment #25
jmarkel CreditAttribution: jmarkel commentedFirst shot at a D7 backport.
Comment #26
pingers CreditAttribution: pingers commentedwell, that seems good :)
Tested locally without the fix, test failed.
Tested locally with the fix, test passed.
Comment #27
webchicknice fix, nice test!
committed and pushed to 7.x. thanks!