I just came across this. If you have any upper case in your colors in the default array it will color_shift instead of picking out the color from a selected other color set.

Probably in color_get_palette() it just needs to change all values to lower case.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Reg’s picture

For anyone who needs this fixed now adding array_map() to the return line in color_get_palette() solves it. Below is how the changed line looks:

return array_map('strtolower', $default ? $palette : variable_get('color_' . $theme . '_palette', $palette));
Reg’s picture

Version: 7.x-dev » 8.x-dev
Devin Carlson’s picture

Reg’s picture

Status: Closed (duplicate) » Active

The issue that this was marked as duplicate however the issue it was specified as being a duplicate of an isse that makes mention of a "notice" error is being produced. This is NOT the case here. The issue here is purely that there is a logic error in how case for colors is handled in the color module.

That is, no "notice" message was ever observed. I suspect that the "notice" message was fixed through the Drupal versions since the other issue is so old. The issue here of "case and color shifting" has yet to be resolved so I am changing this issue back to active.

Anonymous’s picture

#1 as a patch file.

Anonymous’s picture

Status: Active » Needs review
markhalliwell’s picture

Status: Needs review » Needs work

Patch makes sense and is straight forward. However, please re-roll with the new Drupal::config() that's now in place.

markhalliwell’s picture

tagging

markhalliwell’s picture

Actually you should probably map to drupal_strtolower() instead, which is really just a wrapper around Unicode::strtolower(). Either should work.

RainbowArray’s picture

Assigned: Unassigned » RainbowArray
RainbowArray’s picture

Status: Needs work » Needs review
FileSize
521 bytes

This was a bit more than a reroll. Here's an updated patch.

Status: Needs review » Needs work

The last submitted patch, lower-case-colors-1415206-11.patch, failed testing.

RainbowArray’s picture

Status: Needs work » Needs review
FileSize
601 bytes

Re-did the patch.

Confession: I hope I did this correctly, but not entirely sure.

The original code that the patch in #5 was trying to fix was as follows:

return $default ? $palette : variable_get('color_' . $theme . '_palette', $palette);

The suggested patch was:

return array_map('strtolower', $default ? $palette : variable_get('color_' . $theme . '_palette', $palette));

However, since that patch on July 29, 2012, the color.module was updated to the following line:

return config('color.' . $theme)->get('palette') ?: $palette;

Here's the approach I tried.

return Unicode::strtolower(Drupal::config('color.' . $theme))->get('palette') ?: $palette;

I changed the config() to Drupal::config() and wrapped that in Unicode::strtolower() as suggested in #7 and #9. I'm not sure if an array_map is what's needed here?

Anyhow, if somebody could take a look, that would be great. Thanks!

markhalliwell’s picture

Status: Needs review » Needs work

Hi @mdrummond :) Thanks for working on this issue and submitting patches!

I suspect this patch will fail as well. The errors from the first test indicates that strtolower needs the parameter to be a string and we're passing the CMI setting (which is the array). From reading the issue, the patch in #5 is attempting to use array_map() to lower case the values of the array (see: http://stackoverflow.com/questions/4445984/strtolower-on-a-array).

This being said, I'm not entirely what is being returned by the new CMI (ie: if it's the same simple array as before). Try doing this:

return array_map('drupal_strtolower', Drupal::config('color.' . $theme))->get('palette') ?: $palette);

My comment about using drupal_strtolower or Unicode::strtolower, was I'm not entirely sure what should be passed as the first parameter in array_map: array_map('drupal_strtolower', array_map('Unicode::strtolower'... or I think this would actually work as a valid callback: array_map(array('Unicode', 'strtolower')

RainbowArray’s picture

Okay, let's see if this patch passes!

markhalliwell’s picture

Status: Needs work » Needs review

Triggering test bot

Status: Needs review » Needs work

The last submitted patch, default-color-scheme-1415206-15.patch, failed testing.

RainbowArray’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, default-color-scheme-1415206-15.patch, failed testing.

markhalliwell’s picture

@@ -132,7 +132,8 @@ function color_get_palette($theme, $default = FALSE) {
+  return array_map('drupal_strtolower', Drupal::config('color.' . $theme))->get('palette') ?: $palette);

Ah! I see the problem. The array_map() function is getting closed too early. See the extra ) at the end of: Drupal::config('color.' . $theme))

RainbowArray’s picture

Status: Needs work » Needs review
FileSize
534 bytes

One would think that eventually I would get this patch right. One will soon see.

jOksanen’s picture

markhalliwell’s picture

Status: Needs review » Needs work
Issue tags: -Needs reroll +Needs manual testing
+++ b/core/modules/color/color.module
@@ -132,7 +132,7 @@ function color_get_palette($theme, $default = FALSE) {
   // Load variable.
   // @todo Default color config should be moved to yaml in the theme.

One tiny nitpick (that I just noticed). This comment should probably be removed and replace with something says it loads the saved configuration palette or the default one if it doesn't exist. It also converts values to lowercase hexes. Follow documentation standards at https://drupal.org/node/1354#drupal and https://drupal.org/node/1354#inline.

Didn't need to re-test, it passed. I'm hesitant to tag as needs tests, this is a very minor change and can be covered with the above inline comment.

mgifford’s picture

Assigned: RainbowArray » Unassigned
Issue summary: View changes

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

partyka’s picture

Issue tags: +Novice, +Global2020
NitinLama’s picture

Assigned: Unassigned » NitinLama
FileSize
940 bytes

Added return statement with comments.

NitinLama’s picture

Assigned: NitinLama » Unassigned
Status: Needs work » Needs review
ayushmishra206’s picture

Status: Needs review » Needs work

@NitinLama We cannot have a comment exceed 80 columns due to coding standards. It needs to wrap onto the next line.

NitinLama’s picture

Status: Needs work » Needs review
FileSize
953 bytes

Updated comment.

g-brodiei’s picture

Status: Needs review » Needs work

Nice work!!

Was reviewing as I went searching through D8.9.x, and it seems like the callback function "drupal_strtolower" only exist in D7's Unicode.inc file.

Back to need work if this patch is to be ported to D8.

Posting D7 version code for reference, might reconsider using mb_strtolower() as part of a callback function for array_map as an alternative to the Unicode::strtolower suggestion before since it's gonna be deprecated in D9.

/**
 * Lowercase a UTF-8 string.
 *
 * @param $text
 *   The string to run the operation on.
 *
 * @return string
 *   The string in lowercase.
 *
 * @ingroup php_wrappers
 */
function drupal_strtolower($text) {
  global $multibyte;
  if ($multibyte == UNICODE_MULTIBYTE) {
    return mb_strtolower($text);
  }
  else {
    // Use C-locale for ASCII-only lowercase
    $text = strtolower($text);
    // Case flip Latin-1 accented letters
    $text = preg_replace_callback('/\xC3[\x80-\x96\x98-\x9E]/', '_unicode_caseflip', $text);
    return $text;
  }
}
shetpooja04’s picture

Status: Needs work » Needs review
FileSize
2.11 KB
1.1 KB

I have added the drupal_strtolower function definition in D8.9.x
Please review !
Thank you

g-brodiei’s picture

Status: Needs review » Needs work

Thanks for the effort on creating a new patch! Just a few things we need to check before moving forward.

The function drupal_strtolower($text) was deprecated and removed when upgrading from Drupal 7 to Drupal 8 for a reason, I don't think we should be adding it back into Unicode.inc file again. Let's just use "mb_strtolower" instead in the array_map function, this was what I saw changed in the _color_rewrite_stylesheet function comparing Drupal 7 to Drupal 8.

We still need to update the "issue summary" and do a "manual testing" to assure this patch is good before setting to "RTBC". Follow the guidelines on Issue summary and Manual testing for further information. ;) Thanks!

Going back checking on core's git history, the removal action of drupal_strtolower function happened in the following issues #2361825: Remove drupal_strtolower, #2361823: Remove usage of drupal_strtolower(), and see #2350615: [policy, no patch] What changes can be accepted during the Drupal 8 beta phase? for the policy reason for this deprecation change.

Drupal 8 color.module

/**
 * Rewrites the stylesheet to match the colors in the palette.
 */
function _color_rewrite_stylesheet($theme, &$info, &$paths, $palette, $style) {
  // Prepare color conversion table.
  $conversion = $palette;
  foreach ($conversion as $k => $v) {
    $v = mb_strtolower($v);
    $conversion[$k] = Color::normalizeHexLength($v);

Drupal 7

/**
 * Rewrites the stylesheet to match the colors in the palette.
 */
function _color_rewrite_stylesheet($theme, &$info, &$paths, $palette, $style) {
  $themes = list_themes();
  // Prepare color conversion table.
  $conversion = $palette;
  foreach ($conversion as $k => $v) {
    $conversion[$k] = drupal_strtolower($v);
naresh_bavaskar’s picture

Assigned: Unassigned » naresh_bavaskar
naresh_bavaskar’s picture

Assigned: naresh_bavaskar » Unassigned
Status: Needs work » Needs review
FileSize
968 bytes
1.61 KB

Updated the mb_strtolower in array_map function as drupal_strtolower was removed from d8.
Please review

guilhermevp’s picture

Status: Needs review » Reviewed & tested by the community

Patch still applies and is working as intended. Moving to RTBC.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs issue summary update, -Needs manual testing, -Novice, -Global2020 +Needs tests, +Bug Smash Initiative
  1. +++ b/core/modules/color/color.module
    @@ -178,13 +178,10 @@ function color_get_palette($theme, $default = FALSE) {
    -  return \Drupal::configFactory()->getEditable('color.theme.' . $theme)->get('palette') ?: $palette;
    ...
    +  return array_map('mb_strtolower', Drupal::config('color.' . $theme)->get('palette') ?: $palette);
    

    We're changing behaviour here, previously it was color.theme.{theme} now it is just color.{theme}

  2. +++ b/core/modules/color/color.module
    @@ -178,13 +178,10 @@ function color_get_palette($theme, $default = FALSE) {
    +  // It loads the saved configuration palette
    +  // Or the default one if it doesn't exist.
    +  // It also converts values to lowercase hexes.
    

    This comment is wrapped prematurely and we're losing a lot of the previous comment. Let's just add a sentence to the existing comment - something along the lines of.
    Ensure that hex values are cast to lowercase to ensure case-insensitivity.

Also, as this is a bug-fix, it would be good if we had some test-coverage that demonstrated the bug, and that the fix applied here resolves it.

Given the change made at item 1 didn't break any tests, I'm guessing there isn't much in the way of existing test-coverage for color module.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Project: Drupal core » Color backport
Version: 9.4.x-dev » 2.x-dev
Component: color.module » Code

Color has been removed from core, #3270899: Remove Color module from core.