Closed (fixed)
Project:
EU Cookie Compliance (GDPR Compliance)
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
17 May 2019 at 08:26 UTC
Updated:
10 Oct 2020 at 16:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
lamp5Comment #3
lamp5Comment #4
lamp5Comment #6
lamp5Remove additional # in css.
Comment #8
svenryen commented@lamp5, could you please share steps to reproduce?
I opened my configuration page on a site with Eu Cookie Compliance 1.5 and when I change the text or background colors to any valid hex value, I could perfectly save the settings without any problems and the banner and/or text color changed to reflect the new colors that I entered.
Comment #9
svenryen commentedWe can't accept your patch in #6 (the one numbered 3). You're removing the # that's in front of the color value, and that will cause 90000 sites that currently entered the color with no # in front to break. You're also removing a class identifier from the generated strings, which may also break somebody's site.
Comment #10
lamp5Complete steps to reproduce:
$element['#value']Comment #11
svenryen commentedThanks, that clears things up. I'll try to install the library and see how it works. Seems like there's been a change since Drupal 7.
For a workaround, try setting the colors without using the popup color picker library.
Comment #12
krzysztof domańskiMake the hash sign as optional and strip it after saving. The user should still enter the color without the hash sign. However, if hash is added, e.g. by a user or by a colorpicker, it will be deleted during the saving.
We can use the Core's
\Drupal\Component\Utility\Color::validateHex()method to validate the hexadecimal color. In this validation, Hash prefix is optional.@lamp5 Probably you can save the colors now. However I didn't test it using the colorpicker. Someone has to test this patch...
I'm not sure what will happen when you need to re-edit colors. After saving, the values will be without the hash sign. Will colorpicker display the correct color then?
Comment #13
svenryen commentedLooks good. Thanks for the patch. @lamp5, would you mind testing the patch?
Comment #14
lamp5After applying this patch, I can save a form, colors are also correct display on cookie popup but color picker values are reset to empty values.
Comment #15
krzysztof domańskiLet's add the leading "#" in the form elements. It will be possible to use a colorpicker to set the colors.
For backward compatibility, colors are STILL stored without a hash sign.
Comment #16
lamp5Patch #15 works, but in my opinion, we should add post-update hook to update existing colors values to proper format instead of checking these conditions. @svenryen what are you thinking about this?
Comment #17
krzysztof domański1. Updating existing colors values to proper format (with a leading hash) is also fine. I added a new patch with the update.
2. Current regular expression (
/^[0-9a-fA-F]{3,6}$/) allows values with 4 or 5 characters (e.g.'ffff'or'00000'') so I changed to/^#([0-9a-fA-F]{3}){1,2}$/.See also Hexadecimal validation returns true if the color contains multiple hashes (e.g. '###FF0').
Comment #18
svenryen commentedThanks. Would you be able to review patch #17, @lamp5?
Comment #19
lamp5#17 works well.
Hook update convert colors values to the correct format, submitting settings form and displaying correct color on cookie popup also works.
So, in my opinion, it is ready to change the status to RTBC
Comment #20
idebr commentedDrupal Core has a utility class that validates hexadecimal values:
\Drupal\Component\Utility\Color::validateHex(). I suggest we reuse that validation instead of writing our own.Comment #21
svenryen commentedNice, yes, we should definitely use
validateHex.Comment #22
krzysztof domański1. In
validateHex()method hash prefix is optional. Colorpicker requires a leading hash so we must add the hash, when we display the form.2. See #15. This is a patch using
\Drupal\Component\Utility\Color::validateHex().3. IMO the
\Drupal\Component\Utility\Color::validateHex()method is unnecessary here. This/^#([0-9a-fA-F]{3}){1,2}$/regular expression is short and understandable.4. We do not have any automatic tests in this module. Without testing, code maintenance will be more problematic if the hash is optional. If the hash is required, we do not have to worry about removing it or adding it while displaying or saving the form.
5. In older versions of Drupal (e.g. 8.6) there is an error Hexadecimal validation returns true if the color contains multiple hashes (e.g. '###FF0'). It will be introduced in the new version 8.7.4.
Comment #23
svenryen commentedIf we are having issues with Drupal versions prior to 8.6, I agree with @Krzysztof Domański here.
We can use the reg ex proposed in #17.
I'm going to double check that colorpicker works as expected in D7 and D8 and then will commit this patch later.
Comment #24
svenryen commented@Krzysztof Domański, I installed
jquery_colorpicker version 1.4(which is what composer gives by default if you don't specify:^2). Without applying your patch I had no problems saving the EU Cookie Compliance settings form, and the banner was shown with the proper colors.I then did some searching.. If I can guess, you're probably using
jquery_colorpicker version 2.0-rc1and we have a problem.The requirements of a # in front of the hex is a backwards-compatible breaking change in
jquery_colorpicker 2.0, and we need to support both versions.This issue needs work. Either we need to write a patch that removes the support for jquery_colorpicker, or our code for Drupal 8 needs some if/else to support both version 1 and 2. Possibly, stripping # if present after form submit and before saving would be the best option.
I haven't looked at the previous patches, so if there's code in comment 2, 3, 12 or 15 that works with both jquery_colorpicker 1.x and 2.x, please let me know and I'll take another look.
Comment #25
svenryen commentedThis issue have become outdated. I have no problems setting the color using
jquery_colorpicker 8.x-2.0-rc1.Feel free to reopen if you're still having these issues.
Comment #26
svenryen commentedReopening this issue as I was having issues with jquery_colorpicker 2.x after a reinstall.
Comment #27
svenryen commentedHere's a patch that fixes the issue and that works with both version 1 and 2 of jQuery Color Picker.
Comment #28
neslee canil pinto@svenryen #27 worked like a charm. +1 for that.
Comment #30
neslee canil pinto