Color css files are not regenerated when deploying through configuration management

Created on 29 August 2018, about 6 years ago
Updated 19 December 2023, 11 months ago

Problem/Motivation

If a theme's colour scheme is changed, a stylesheet (specifically colours.css and also logo.svg) is created in /sites/default/files/color/bartik-[hash]/ and a new directory with a different hash is used each time.

When using config synchronisation, the color.theme.bartik.yml file is copied, but the default .gitignore file excludes sites/*/files, therefore the production server will be missing the required CSS and have a mostly a mostly white page.

Visiting /admin/appearance/settings/bartik on production and clicking Save Configuration will fix the site, but unfortunately will also generate a new directory with a different hash and a new .yml file on config export, further complicating matters.

Proposed resolution

The color module already implements a ColorConfigCacheInvalidator event subscriber that listens to config changes. And we also may have config overrides for domains (and at least in theory we can have colors per language ;-) . To support all these:
* factor out file generation
* make the target location predictable by using a deterministic hash
* Regenerate files if needed in hook_library_info_alter() (so this is triggered by ColorConfigCacheInvalidator too)

Remaining tasks

  • Write simple patch

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom wturrell

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom niklp Nottingham

    We needed this for an Opigno-based project so I re-rolled #68 against 1.0.3 if helpful.

  • πŸ‡¬πŸ‡§United Kingdom niklp Nottingham

    Updated patch to remove casting errors and improper string var to function.

  • πŸ‡§πŸ‡¬Bulgaria alexrayu

    Fix from #68 for color in 9.4.x with PHP 8.1 deprecation fix in rgbToHex().

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Patch Failed to Apply
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    5 pass, 2 fail
  • πŸ‡ΊπŸ‡ΈUnited States dpagini

    I want to set this to "Needs review", maybe even RTBC... I don't know why, but I can't set one of these patches to test against the 2.x branch, so it shows that it fails to apply to 1.x. I am using the 1.x version of the patch in my project, and it is solving this issue for me... I'm curious if this task has some actionable steps now to document?

  • The last submitted patch, 71: 2995825-71.patch, failed testing. View results β†’
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • πŸ‡¬πŸ‡§United Kingdom niklp Nottingham

    We've been using the patch from #73 since it arrived, without issue.

  • πŸ‡ͺπŸ‡ͺEstonia rang501 Viljandi

    I tested on the 1.x version and Drupal 10.1. The patch in #73 fails to apply, #72 works fine, and did not see any issues with aggregation as well.
    It seems to work as expected, but I'm not sure if making methods private is a good idea - decorating the service is problematic. I need to duplicate many methods to apply some additional color replacement logic there.

  • Status changed to Needs work 11 months ago
  • πŸ‡ͺπŸ‡ͺEstonia rang501 Viljandi

    There is a bug inside the hash calculation. The $cache_context_keys is not different and the problem appears when there are two themes enabled (in my case, the main theme and sub-theme). The [theme]= context key is wrong, it was gin (admin theme), not the theme that was provided as a function parameter, so the hash was the same and it generated one set of the CSS files and skipped it later because the hash was in cache already.

    So I added this before the hash function:

        foreach ($cache_context_keys as $key => $value) {
          if (str_starts_with($value, '[theme]')) {
            $cache_context_keys[$key] = '[theme]=' . $theme;
          }
        }

    then it started to work.

Production build 0.71.5 2024