Updated: Comment #28
Problem/Motivation
Themes providing color integration need a color.inc file. Many of the keys in that file should be optional, but are assumed to be declared.
For example, Bartik has to declare 'fill', 'slices', and 'base_image', even though none are used, and additionally has to provide an actual base.png file that is never used.
Proposed resolution
Provide sane defaults inside color_get_info(), and use isset() checks for optional keys.
Remaining tasks
N/A
User interface changes
N/A
API changes
API "addition": themes wishing to provide color support only have to specify values in their color.inc if they need them. Sane defaults are added.
Original report by @Jeff Burnz
color_scheme_form_submit() does a resource check to make sure theres enough memory to generate a color set, as part of that check it sets a variable $source = drupal_get_path('theme', $theme) . '/' . $info['base_image'];
, but does not check if $info['base_image']
is set.
Later in the same function it does check:
// Render new images, if image has been provided.
if ($info['base_image']) {
_color_render_images($theme, $info, $paths, $palette);
}
There are a couple of reasons why this is a bug:
1) Colorable themes should not require a base image - Bartik currently has one but its never used, its there purely to avoid an error (Bartik does not generate any colorized images).
2) Its inconsistent - in one place we check, in another we do not.
If we don't fix this every colorable theme for the entire D7 lifetime will require a base image just to avoid generating an error, even when they don't even need a base image.
Comment | File | Size | Author |
---|---|---|---|
#31 | color-924322-31.patch | 10.69 KB | tim.plunkett |
Comments
Comment #1
sun.core CreditAttribution: sun.core commentedSo you're basically trying to make base_image optional. That's probably a good idea, but neither a bug, nor major.
Comment #2
tim.plunkettTagging for D8, not sure about backportability, depends on how we fix it.
Comment #3
Devin Carlson CreditAttribution: Devin Carlson commentedThis is a pretty big WTF when you first start digging into how to make a theme recolorable. I don't care about the issue category but I'd call this a bug since the color module requires you to define/include an unused image file in your theme in order to change a single hex string without throwing errors.
The attached patch checks to see if base_image is set in both places mentioned in the original issue. This allowed me to remove the reference to base.png in my theme's color.inc files and not receive any errors. This should be safe to backport to Drupal 7 as existing themes do not need to be modified.
Comment #4
Devin Carlson CreditAttribution: Devin Carlson commentedTagging as novice.
Comment #5
Danny_Joris CreditAttribution: Danny_Joris commentedI'm new to patch testing, but I installed D8 and successfully applied the patch. I want to test the patch, but I don't understand the issue fully.
As a test I renamed base.png and preview.png, cleared cache, modified bartik's colors and saved.
The preview worked fine and the changes also got applied to the theme.
However I did get this error message after saving:
Please help me review this. Thanks. :)
Edit - it's actually the same error as when there is no patch applied. The base image probably gets called somewhere, still?
Comment #6
Danny_Joris CreditAttribution: Danny_Joris commentedI restored the .png files, but instead I commented out 'base_image' => 'color/base.png', in color.inc.
Without patch it threw errors and with patch it didn't :)
Didn't see any difference in my actual theme or the preview, though, without the .png files or without 'base_image' defined. I'll have to look into what it actually does.
Comment #7
Devin Carlson CreditAttribution: Devin Carlson commentedRe-rolled patch now that D8 moved everything into /core.
Comment #8
Jean Gionet CreditAttribution: Jean Gionet commentedFresh install of Drupal 7.10 I get this error message prior to applying the latest patch from post #3
After applying the latest patch:
and clearing cache I still get the same errors
Line 312 still gets called.
list($width, $height) = getimagesize($source);
Comment #9
tim.plunkettComment #10
mike stewart CreditAttribution: mike stewart commentedWorks as expected against D8. However, using Bartik to test is probably not ideal. Is there another theme that doesn't have base images?
If you use barktik to test, instructions for test case seems to be to remove:
rm core/theme/bartik/color/base.png
rm core/theme/bartik/color/preview.png
However, since bartik comes with images, it also sets 'base_image' => 'color/base.png' (which is why @Jean Gionet encountered the error) Bartik thinks is needs images... and when removing them, then you no longer need (and shouldn't) set 'base_image'
so I commented that out line 131 of core/themes/bartik/color/color.inc to:
//'base_image' => 'color/base.png',
and works as expected.
It probably makes sense to have another test case... so I'm not going to RTBC. But I'm pretty confident this works if there was a clean test case.
Comment #11
Jean Gionet CreditAttribution: Jean Gionet commentedas @mike stewart indicated, if you comment out line 131 from the color.inc file from the Bartik theme no errors are displayed. (so the patch does work)
I'm assuming that the Bartik theme would have to be updated at the same time if this patch is to be rolled out.
Comment #12
mike stewart CreditAttribution: mike stewart commentedI've submitted issue #1366594: Remove Color Module Base Image Dependency from Bartik with a patch which will fix Bartik to remove uneeded base_image. The patched version from 1366594 of Bartik can then be used as a unit test for this issue -- plus cleans up Bartik.
To test:
First apply patch from #7 of this issue. Then apply patch from #1366594: Remove Color Module Base Image Dependency from Bartik to use as unit test of #7 above.
Comment #13
mike stewart CreditAttribution: mike stewart commentedThis issue has two unit test cases. Themes that have/use base_images, and theme's that don't.
1) The patch in #7 works for the first case: in a theme that has base_image is set -- such as current state of Bartik -- and that's a good test case for themes that use image.
2) This issue is about eliminating the requirement of color-able images (and hence the need for the base_image to be set). But due to this bug, D8 only has themes with color-able images. (Bartik) So I created #1366594: Remove Color Module Base Image Dependency from Bartik
However, the patch I submitted for #1366594 failed. If I understand the error log from the test, it seems it failed due to fact this issue hasn't been committed. So I've created a combo "test patch" (attached) that will allow us to patch both and use for second test case.
So how this should work:
1) Apply patch #7 to a clean Drupal 8.x setup.
2) Then test if you can change colors in Bartik. It should work without manual modification of files. This shows the patch works with Themes that have base_image set.
3) Then revert to a clean Drupal 8.x setup.
4) Apply the attached patch. (a combo of #7 plus the #8 patch to Bartik #1366594)
5) Repeat the test to change colors in Bartik. It should work. The test this time however is against Bartik without base_image set. If it passes it proves the requirement for base_image is removed and test in #2 shows it functions on themes that have it.
Alternatively, do steps 1 & 2 above, then apply patch #8 from #1366594 instead of steps 3 & 4. Step 5 should be same results.
Assuming everything is good. It should be proof the #7 above works as stated and can be RTBC. Which should also allow #1366594: Remove Color Module Base Image Dependency from Bartik to move forward.
Comment #14
Jean Gionet CreditAttribution: Jean Gionet commentedafter a clean D8 install,
then applying patch #7 of this post
and applying patch #8 from Mike Stewart's Bartik theme post everything is loading error free.
Comment #15
BTMash CreditAttribution: BTMash commented+1 on the rtbc. Its working as expected.
Comment #16
xjmNice, this is a surprisingly simple patch for such a WTF-y issue. It sounds like this fix is also needed to unblock #1366594: Remove Color Module Base Image Dependency from Bartik, which in turn is needed to add the test coverage described in #13? Is that the case?
Edited.
Comment #17
tim.plunkettCNW for tests.
Comment #18
xjm#13: test-patch-bartik-without-base-image-924322--13.patch queued for re-testing.
Comment #19
BrockBoland CreditAttribution: BrockBoland commentedResetting to CNW for tests.
Comment #20
wadmiraal CreditAttribution: wadmiraal commentedTest is on the way
Comment #21
softescu CreditAttribution: softescu commentedOk. I am looking now for other themes to replicate the issue.
Comment #22
wadmiraal CreditAttribution: wadmiraal commentedI see we're kinda working on the same thing here: http://core.drupalofficehours.org/task/746 and http://core.drupalofficehours.org/task/420 :-).
But in this case, both tests would definitely overlap, which is a waste of time, no ?
You're in the code sprint room :-) ? If so, where are you seated ? I'm in the back, far right (next to Webchick).
Comment #23
wadmiraal CreditAttribution: wadmiraal commentedThis is actually covered by the core test.
If you apply the patch from #1366594: Remove Color Module Base Image Dependency from Bartik to Bartik, you remove the base image. In that case, the tests fail. That's what this issue is all about.
THEN, if you apply the patch from #7, the tests pass, because it removes the necessity to have a base image.
Just to be sure, if you revert the patch to Bartik (which means you still use a base image), and run the tests, they still pass (as they should).
So, as stated in #16, this should be rolled as a single issue / patch (as in #13).
As a side note: how could we include tests that include a base image for recoloring ? Bartik doesn't do it, no other core theme does. Should a new theme be included, just for testing purposes ? Could themes be hidden, just like modules, for testing ?
Comment #24
markhalliwellUnlike @sun (and now the component maintainer for color), I agree with #3. Categorizing this back to a major bug. Also not sure about backport compatibility, but will leave the tag for now.
Comment #25
markhalliwellComment #26
Alex Dicianu CreditAttribution: Alex Dicianu commentedRerolled the patch as instructed here https://drupal.org/patch/reroll. I also applied the patch to a clean d8 install and I was able to modify Bartik's colors, but some more experienced testers might need to have a look.
PS: this only my second patch reroll so please tell me if I'm doing something wrong.
Comment #27
Jeff Burnz CreditAttribution: Jeff Burnz commentedA plausible solution could be to remove this entire functionality form Color module. It harks back to the days of yor before we had things like CSS gradients. Garland was one of the very few themes ever built that used this feature, and could quite easily be converted to use CSS gradients. I think John Albin is the maintainer so we could ask him what he thinks about that.
Basically this issue is stuck because of this catch 22 - can't test it, can't not test it. Maybe just remove it.
Comment #28
tim.plunkettAdjusting the scope a bit.
We should be making a color.inc file as simple as possible to author by providing sane defaults and not assuming that optional keys are set.
I added test coverage, and removed the superfluous changes around the memory limit.
Because there are several hunks that are just indentation, providing a git diff -w patch as well.
Comment #29
tim.plunkettGrr, we don't need this, I'll have to remove it. I'll wait for the patches to come back first.
Comment #31
tim.plunkettOkay, that passed and failed accordingly. Removed the stray CSS file from my earlier testing. This should be good now.
Comment #32
markhalliwell@tim.plunkett this is awesome! Thanks for taking this on. I've reviewed the patch, code is perfect (naturally :) and solves the original report and then some. Test only patch failed and latest patch is green. Marking RTBC.
Comment #33
webchickThis looks like great clean-up. Committed and pushed to 8.x. Thanks!
Moving down to 7.x.