This was brought up #781594: Bartik's color integration misses 'base' key but it isn't an issue with Bartik but the Color module as far as I am concerned.

Can we add some logic here to verify that $base is set before calling _color_shift()?

429     if ($is_color) {
430       $chunk = drupal_strtolower($chunk);
431       // Check if this is one of the colors in the default palette.
432       if ($key = array_search($chunk, $default)) {
433         $chunk = $conversion[$key];
434       }
435       // Not a pre-set color. Extrapolate from the base.
436       else {
437         $chunk = _color_shift($palette[$base], $default[$base], $chunk, $info['blend_target']);
438       }
439     }

I hate seeing notices like:

# Notice: Undefined index: base in _color_rewrite_stylesheet()  (line 437 of /home/dm7/modules/color/color.module).
CommentFileSizeAuthor
#3 789554-show-added-palette-fields.patch671 bytesStevel
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mgifford’s picture

Adding link to confirmation that this is a problem with core and not just the theme it was discovered in.
#781594-8: Bartik's color integration misses 'base' key

joachim’s picture

As far as I could work it out, the problem is that $base is set, but it is set to the string 'base', which happened to not be in the Bartik palette.

Stevel’s picture

Status: Active » Needs review
FileSize
671 bytes

I just got the same error. Looks like this happens when an extra colorable field is added in the theme. The theme settings page tries to load the 'current' (i.e. customized) palette which does not include the new field yet.

This causes the field 'base' not to be shown on the theme settings page, and thus is not submitted, which in turn causes the index not existing.

This patch merges the current version with the default palette (and thus new fields are shown with their default value).l

Stevel’s picture

mgifford’s picture

Steve, do you have a path for others to test this? Both the bug and how to fix it.

When do folks get this notice and is it still a problem in core?

joachim’s picture

IIRC and from my own earlier comments, the problem is caused by trying to change colours on a theme that does not have a palette item called 'base'.

Stevel’s picture

To reproduce the error, add a new color to $info['fields'] and $info['schemes'][*]['colors'] in e.g. themes/bartik/color/color.inc and try saving the theme settings.

Thus the error only occurs when a theme is updated (core or contrib), adding a new color to the palette.

mgifford’s picture

Ok, I tried to repeat the problem with:


Index: themes/bartik/color/color.inc
===================================================================
RCS file: /cvs/drupal/drupal/themes/bartik/color/color.inc,v
retrieving revision 1.6
diff -r1.6 color.inc
18a19
>     'Mouse' => t('Mouse'),
33a35
>         'Mouse' => '#fffeff',
47a50
>         'Mouse' => '#fffeff',
61a65
>         'Mouse' => '#fffeff',
75a80
>         'Mouse' => '#fffeff',
89a95
>         'Mouse' => '#fffeff',

But I couldn't get the error again so I can't verify that anything was fixed.

clayball’s picture

I'm receiving this Notice after I copied over a custom Bartik sub-theme from another site.
Everything was fine until I enabled the sub-theme and modified the header colors.

The is_color check is there and I still receive this Notice.

clayball’s picture

I just fixed this by setting the sub-theme to the default color scheme and then modified the sub-themes color.css file by hand. There still seems to be an issue somewhere as this work around should not be required.

King of Picts’s picture

Status: Needs review » Needs work

The last submitted patch, 789554-show-added-palette-fields.patch, failed testing.

sonny30’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 789554-show-added-palette-fields.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Closed (duplicate)

I believe this is the same issue as #1236098: Notice: Undefined index: 'base' in _color_rewrite_stylesheet()

Despite this being opened first, the other more clearly describes the problem, so marking this one as a duplicate.

cerr’s picture

Hi,

I'm getting this error:
Notice: Undefined index: text in _color_rewrite_stylesheet() (line 479 of /home/content/80/9693280/html/site/modules/color/color.module).
After I tried to change colors in color.css manually with Corporate Clean - how dio I fix this? Now my colors seem to be almost random... :o

Thanks!

geek-merlin’s picture

Version: 7.x-dev » 8.8.x-dev
Issue summary: View changes
Status: Closed (duplicate) » Active

This is still an issue with current dev. The supposed dup was closed 9 years ago for bartik.

As correctly analyzed by @joachin in #6, this happens for any theme that does not declare an entry named "base" in its palette.

The offending code...

  $base = 'base';
...
      // Not a pre-set color. Extrapolate from the base.
      else {
        $chunk = _color_shift($palette[$base], $default[$base], $chunk, $info['blend_target']);
      }

... obviously extrapolates colors not registered in the palette and needs a base color for this.

We could proceed in 2 ways:
a) Make the 'base' color a requirement for any theme and fix bartik for that
b) Use the first available color for $base if no 'base' key present.

After reading the _color_shift function's comment, i'm pragmatically for b).
After reading some more, i'm undecided...

geek-merlin’s picture

Status: Active » Closed (duplicate)

Ups, i had the wrond dup, so closing again.

emb03’s picture

Status: Closed (duplicate) » Active

This is still an issue. I am using a subtheme of a subtheme and when I try to change the color in the theme to a different color, I get this error: Notice: Undefined index: base in _color_rewrite_stylesheet() (line 553 of core/modules/color/color.module). and the theme does not change color.

Can someone finally fix this after 9 years? Thanks.

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.

selinav’s picture

Same probleme for me in the last version of Drupal 8.9.3 and a subtheme of bootstrap barrio.
Any idea how to fix it ?

SocialNicheGuru’s picture

what is the syntax for defining the "base" color in the theme?

marvil07’s picture

Status: Active » Closed (duplicate)

Back to closed as duplicated of #1236098: Notice: Undefined index: 'base' in _color_rewrite_stylesheet(), following the reasoning at #789554-15: Notice: Undefined index: base in _color_rewrite_stylesheet() in line 437.

Despite this being opened first, the other more clearly describes the problem, so marking this one as a duplicate.

Let us continue there instead of re-opening this one.