Statistics page should render without color module being installed

Created on 6 January 2022, almost 3 years ago
Updated 9 November 2023, about 1 year ago

Problem/Motivation

The statistics page currently requires a theme that utilizes the Color module.

Steps to reproduce

  1. In an Opigno LMS site, create a sub-theme of Aristotle.
  2. Visit the /statistics/dashboard path.
  3. See warnings about the offset.

Proposed resolution

To avoid adding a hard dependency, it would be better to first check the existence of Color module, then check color_get_info($theme) returns something, and only then try to retrieve a color from color_get_palette().

The module already has a fallback color for charts.

Work around

Ensure your theme supports the color module. In the sub-theme directory:

  1. Create a directory called "color".
  2. Create a file named "color.inc"
  3. Create a file named "color.css"

For reference of how these files should look, you can look at /themes/contrib/aristotle/color/

✨ Feature request
Status

Needs work

Version

3.1

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom catch

Live updates comments and jobs are added and updated live.
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.

  • Encountering Error with Opigno Statistics Module Version 3.1.0 Due to Color Module Dependency

    Hello,

    I am currently using the Opigno Statistics module version 3.1.0 in my Drupal 9 setup with an Opigno distribution. I have encountered the following error:

        Warning: Trying to access array offset on value of type null in Drupal\color\ColorThemeDecorator->getPalette() (line 411 of modules/contrib/color/src/ColorThemeDecorator.php).
        

    The issue seems to be related to the Color module, which is required by the Opigno distribution but not actively used in my theme (s_5_university). I am using a CSS file to manually color my website. (I believe I am using something that is referred to as subtheming)

    I created a color settings file (s_5_university.settings.yml) for my theme, specifying some default colors, and declared support for the Color module in my theme's .info.yml file. However, this did not resolve the issue, and the error persists.

    I understand that there is a patch under review for this issue. I would greatly appreciate it if you could expedite the review process, or suggest any other workaround that could help me resolve this issue.

    Thank you for your assistance.

  • I have a Drupal 9 website with an Opigno distribution. Opigno uses Aristotle as their base theme. I created a subtheme called s_5_university that is the default for the website. This unfortunately messes with the Color module that Opigno requires for some of their functionality. We get the following error:
    Warning: Trying to access array offset on value of type null in Drupal\color\ColorThemeDecorator->getPalette() (line 413 of modules/contrib/color/src/ColorThemeDecorator.php).

    This is because the getPalette function is passed the s_5_university value for the argument $theme here:
    public function getPalette($theme, $default = FALSE) {

    And immediately tries to pass that value to the function color_get_info() here:
    $info = color_get_info($theme);

    The color_get_info looks like the following:
    /**
    * Retrieves the Color module information for a particular theme.
    */
    function color_get_info($theme) {
    static $theme_info = [];

    if (isset($theme_info[$theme])) {
    return $theme_info[$theme];
    }

    $path = \Drupal::service('extension.list.theme')->getPath($theme);
    $file = \Drupal::root() . '/' . $path . '/color/color.inc';
    if ($path && file_exists($file)) {
    include $file;
    // Add in default values.
    $info += [
    // CSS files (excluding @import) to rewrite with new color scheme.
    'css' => [],
    // Files to copy.
    'copy' => [],
    // Gradient definitions.
    'gradients' => [],
    // Color areas to fill (x, y, width, height).
    'fill' => [],
    // Coordinates of all the theme slices (x, y, width, height) with their
    // filename as used in the stylesheet.
    'slices' => [],
    // Reference color used for blending.
    'blend_target' => '#ffffff',
    ];
    $theme_info[$theme] = $info;
    return $info;
    }
    }

    Now I haven't set up any Color module information for my theme s_5_university, and I am not sure exactly what I need to create to feed this function what it needs. It is likely encountering this error because I have no Color module information set up for it to read at this time.

    Resolved

    The color_get_info() function is looking for for a color directory with the color.inc file.

    1. In the subtheme directory create a directory called "color".
    2. In the subtheme directory go into the new directory "color" and create a file named "color.inc"
    3. In the subtheme directory go into the new directory "color" and create a file named "color.css"
    4. For reference of how these files should look, you can go to /themes/contrib/aristotle/color

    This completely resolved my issue as now the color_get_info() function can access the information it is requesting.

  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States jcandan

    Not resolved. But the above solution is a valid work around.

    This issue's premise is sound. This module should not have a hard dependency on the Color module, since an Aristotle sub-theme or other custom theme may opt to not utilize this feature. Additionally, the color module is deprecated in Drupal core as of 9.4, and is removed in Drupal 10. Support for this module is carried via the new contrib module.

    Patch #5 successfully applies, but the Trying to access array offset on value of type null in Drupal\color\ColorThemeDecorator->getPalette() warning persists. I believe we'll need a $palette = \Drupal::service('color.theme_decorator')->getPalette($theme);

Production build 0.71.5 2024