Add validation constraints to `type: theme_settings`

Created on 22 January 2024, 11 months ago
Updated 28 June 2024, 6 months ago

Problem/Motivation

Per #3395555-22: Add validation constraints to olivero.settings ā†’ , type: theme_settings not being fully validatable means not a single theme's settings can be fully validatable!

Steps to reproduce

N/A

Proposed resolution

Determine appropriate validation (and config schema tweaks) for:

  1. theme_settings:favicon.* ā†’ mimetype, path, url only make sense if use_default is set to FALSE. The more elegant solution would be to only allow any key besides use_default if use_default is set to FALSE. But that'd require virtually every theme in existence to modify their default settings. So instead, add validation logic that requires each of these to be NULL if use_default === TRUE, and requires a valid value otherwise.
  2. theme_settings:logo.* ā†’ same as for *:favicon.*
  3. theme_settings:features.* ā†’ this one is very tricky. The last significant work in this area was in 2018, in #2954884: Cannot save theme settings form for themes without logo or favicon features ā†’ . core/modules/system/tests/themes/test_theme_settings_features/test_theme_settings_features.info.yml correctly defines a features key in the theme's *.info.yml file. But not a single core theme does this! šŸ˜± Which means that
    function _system_default_theme_features() {
      return [
        'favicon',
        'logo',
        'node_user_picture',
        'comment_user_picture',
        'comment_user_verification',
      ];
    }
    

    applies to all core themes (or any other theme that doesn't specify features in its *.info.yml).

    AFAICT this means that in principle every theme that specifies features in its *.info.yml with only a subset of _system_default_theme_features() MUST specify a corresponding tweak to type: theme_settings, for example the test_theme_settings_features theme's

    features:
      - node_user_picture
      - comment_user_picture
      - comment_user_verification
    

    SHOULD REQUIRE a corresponding:

    test_theme_settings_features.settings:
      type: theme_settings
      label: 'Test theme settings'
        features:
          type: mapping
          label: 'Optional features'
          mapping:
            comment_user_picture:
              type: boolean
              label: 'User pictures in comments'
            comment_user_verification:
              type: boolean
              label: 'User verification status in comments'
            node_user_picture:
              type: boolean
              label: 'User pictures in posts'
    

    ā€¦ and the absence of this config schema tweak should result in a deprecation error.

    Similarly, the absence of default configuration ā†’ for each of these should also result in a deprecation error.

    This part definitely requires theme subsystem maintainer review.

FYI, previous work on this area:

Merge request link

Remaining tasks

Get theme subsystem maintainer approval for the proposed resolution.

User interface changes

None.

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

šŸ“Œ Task
Status

Needs work

Version

11.0 šŸ”„

Component
ThemeĀ  ā†’

Last updated 4 days ago

Created by

šŸ‡§šŸ‡ŖBelgium wim leers Ghent šŸ‡§šŸ‡ŖšŸ‡ŖšŸ‡ŗ

Live updates comments and jobs are added and updated live.
  • Needs subsystem maintainer review

    It is used to alert the maintainer(s) of a particular core subsystem that an issue significantly impacts their subsystem, and their signoff is needed (see the governance policy draft for more information). Also, if you use this tag, make sure the issue component is set to the correct subsystem. If an issue significantly impacts more than one subsystem, use needs framework manager review instead.

  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @wim leers
  • šŸ‡§šŸ‡ŖBelgium wim leers Ghent šŸ‡§šŸ‡ŖšŸ‡ŖšŸ‡ŗ

    To prepare for working on a MR, I did some git + issue queue archeology and found some surprises:

  • šŸ‡§šŸ‡ŖBelgium wim leers Ghent šŸ‡§šŸ‡ŖšŸ‡ŖšŸ‡ŗ
  • šŸ‡§šŸ‡ŖBelgium wim leers Ghent šŸ‡§šŸ‡ŖšŸ‡ŖšŸ‡ŗ

    Wow, it's even more frightening than I thought: \Drupal\system\Form\ThemeSettingsForm::submitForm() still calls:

    theme_settings_convert_to_config($values, $config)->save();
    

    which looks like this:

    /**
     * Converts theme settings to configuration.
     *
     * @see system_theme_settings_submit()
     *
     * @param array $theme_settings
     *   An array of theme settings from system setting form or a Drupal 7 variable.
     * @param \Drupal\Core\Config\Config $config
     *   The configuration object to update.
     *
     * @return \Drupal\Core\Config\Config
     *   The Config object with updated data.
     */
    function theme_settings_convert_to_config(array $theme_settings, Config $config) {
      foreach ($theme_settings as $key => $value) {
        if ($key == 'default_logo') {
          $config->set('logo.use_default', $value);
        }
        elseif ($key == 'logo_path') {
          $config->set('logo.path', $value);
        }
        elseif ($key == 'default_favicon') {
          $config->set('favicon.use_default', $value);
        }
        elseif ($key == 'favicon_path') {
          $config->set('favicon.path', $value);
        }
        elseif ($key == 'favicon_mimetype') {
          $config->set('favicon.mimetype', $value);
        }
        elseif (str_starts_with($key, 'toggle_')) {
          $config->set('features.' . mb_substr($key, 7), $value);
        }
        elseif (!in_array($key, ['theme', 'logo_upload'])) {
          $config->set($key, $value);
        }
      }
      return $config;
    }
    

    So this is quite literally still Drupal 7 code šŸ˜³

  • Pipeline finished with Failed
    11 months ago
    #80687
  • Pipeline finished with Failed
    11 months ago
    #82315
  • First commit to issue fork.
  • Pipeline finished with Failed
    11 months ago
    Total: 536s
    #83719
  • First commit to issue fork.
  • Pipeline finished with Canceled
    11 months ago
    Total: 203s
    #87951
  • šŸ‡§šŸ‡ŖBelgium svendecabooter Gent

    I have added a commit trying to make the theme_settings.favicon and theme_settings.logo a dynamic type, that only contains the underlying path / url / ... config, if the 'use_default' boolean has been set to false.
    This as per phenaproxima's suggestion.

  • Pipeline finished with Failed
    11 months ago
    Total: 539s
    #87952
  • Status changed to Needs work 11 months ago
  • šŸ‡ŗšŸ‡øUnited States phenaproxima Massachusetts

    This seems like a good start, and a reasonable approach to the problem. I had a few comments.

  • Pipeline finished with Failed
    11 months ago
    Total: 631s
    #92224
  • šŸ‡§šŸ‡ŖBelgium wim leers Ghent šŸ‡§šŸ‡ŖšŸ‡ŖšŸ‡ŗ
  • Pipeline finished with Failed
    9 months ago
    Total: 171s
    #121103
  • Status changed to Needs review 9 months ago
  • šŸ‡§šŸ‡ŖBelgium borisson_ Mechelen, šŸ‡§šŸ‡Ŗ

    The new config validation test is failing, but I don't understand why. This should be increasing the schema coverage?

  • Status changed to Needs work 9 months ago
  • The Needs Review Queue Bot ā†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide ā†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review 9 months ago
  • šŸ‡«šŸ‡·France nod_ Lille

    testbot is having issues

  • šŸ‡§šŸ‡ŖBelgium wim leers Ghent šŸ‡§šŸ‡ŖšŸ‡ŖšŸ‡ŗ

    This needed to a rebase, not a merging in of upstream commits. Now it should work fine again šŸ¤ž

  • Pipeline finished with Failed
    9 months ago
    Total: 177s
    #122088
  • Status changed to Needs work 9 months ago
  • šŸ‡ŗšŸ‡øUnited States smustgrave

    So bad news didn't see the tests run

    But good news is it was the new validator against config.

    Appears to be some threads on the MR now though

  • Assigned to wim leers
  • šŸ‡§šŸ‡ŖBelgium wim leers Ghent šŸ‡§šŸ‡ŖšŸ‡ŖšŸ‡ŗ

    Yeah that rebase didn't help.

    The output shows why:

    $ vendor/bin/drush cr --quiet
    $ vendor/bin/drush config:inspect --statistics > MR.json
     [error]  {
        "assessment": {
    ā€¦
    

    Running the same command locally:

     [warning] Undefined array key "type" TypedConfigManager.php:217
     [warning] Undefined array key "type" TypedConfigManager.php:217
     [warning] Undefined array key "type" TypedConfigManager.php:217
     [error]  {
        "assessment": {
    ā€¦
    
  • Pipeline finished with Failed
    9 months ago
    Total: 599s
    #123205
  • Pipeline finished with Canceled
    9 months ago
    Total: 128s
    #123232
  • Issue was unassigned.
  • šŸ‡§šŸ‡ŖBelgium wim leers Ghent šŸ‡§šŸ‡ŖšŸ‡ŖšŸ‡ŗ

    Unblocked this. Others can continue now šŸ‘

  • Pipeline finished with Failed
    9 months ago
    Total: 554s
    #123236
  • šŸ‡§šŸ‡ŖBelgium wim leers Ghent šŸ‡§šŸ‡ŖšŸ‡ŖšŸ‡ŗ

    āœØ Support SVG files for theme logo setting Needs work landed, which means SVGs are now allowed.

  • Pipeline finished with Failed
    6 months ago
    Total: 643s
    #210784
  • šŸ‡§šŸ‡ŖBelgium svendecabooter Gent

    I rebased the MR branch with the latest 11.x.
    Locally I also got the '5 errors in system.theme.global:' error, thrown in the pipeline output as well.
    I then fixed incorrect config in 2 core themes. When running config:inspect locally, that fixes the issue.
    However, the latest Gitlab CI pipeline still shows this error, plus (unrelated?) phpunit test failures.
    Not sure what's going on there...

  • Pipeline finished with Failed
    6 months ago
    Total: 1277s
    #210820
Production build 0.71.5 2024