third_party_settings in THEME.settings.yml cannot be dependency managed

Created on 10 October 2019, over 4 years ago
Updated 14 May 2024, 19 days ago

Problem/Motivation

#2352949: Deprecate using Classy as the default theme for the 'testing' profile introduced the $defaultTheme property on functional tests and the behavior associated with that. It's proven to work well.

Except in one case: when the theme provides required configuration that depends on a module already being installed. Yes, #474684: Allow themes to declare dependencies on modules hasn't landed yet, but the Seven theme has been doing this for ages, as does https://www.drupal.org/project/claro , which is being added in #3079738: Add Claro administration theme to core .

This causes failures like:

1) Drupal\Tests\claro\Functional\ClaroTest::testRegressionMissingElementsCss
Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for claro.settings with the following errors: claro.settings:third_party_settings.shortcut missing schema

/Users/wim.leers/Work/d8/core/lib/Drupal/Core/Config/Development/ConfigSchemaChecker.php:95
/Users/wim.leers/Work/d8/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php:111
/Users/wim.leers/Work/d8/core/lib/Drupal/Core/Config/Config.php:231
/Users/wim.leers/Work/d8/core/lib/Drupal/Core/Config/ConfigInstaller.php:378
/Users/wim.leers/Work/d8/core/lib/Drupal/Core/Config/ConfigInstaller.php:137
/Users/wim.leers/Work/d8/core/lib/Drupal/Core/ProxyClass/Config/ConfigInstaller.php:75
/Users/wim.leers/Work/d8/core/lib/Drupal/Core/Extension/ThemeInstaller.php:188
/Users/wim.leers/Work/d8/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php:435
/Users/wim.leers/Work/d8/core/tests/Drupal/Tests/BrowserTestBase.php:570
/Users/wim.leers/Work/d8/core/tests/Drupal/Tests/BrowserTestBase.php:398

Discovered this in #3086435: Add automated test coverage for Claro .

Proposed resolution

Install after modules and use the correct container.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Theme 

Last updated 1 day ago

Created by

🇬🇧United Kingdom alexpott 🇪🇺🌍

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.

  • First commit to issue fork.
  • 🇮🇳India _utsavsharma

    Patch for 10.1.x.

  • 🇦🇹Austria hudri Austria

    I think I've got a related problem: My module has theme-specific settings. Previously I just my modules config settings into the root of theme.settings.yml. Inspired by the shortcut module, I now wanted to clean this up and move it into third party settings. Basically I wanted to update my config from

    third_party_settings:
      shortcut:
        module_link: true
    tailwind_jit:
      compile_html_requests: true
      html_input_file: 'foo.css'
      compile_ajax_requests: true
      ajax_input_file: 'bar.css'
    

    to a proper schema

    theme_settings.third_party.tailwind_jit:
      type: mapping
      label: 'Tailwind JIT settings'
      mapping:
        compile_html_requests:
          type: boolean
          label: 'Compile HTML requests'
        html_input_file:
          type: path
          label: 'Uncompiled CSS input file for HTML requests'
        compile_ajax_requests:
          type: boolean
          label: 'Compile Ajax requests'
        ajax_input_file:
          type: path
          label: 'Uncompiled CSS input file for Ajax requests'
    

    and proper third party settings

    third_party_settings:
      shortcut:
        module_link: true
      tailwind_jit:
        compile_html_requests: true
        html_input_file: 'foo.css'
        compile_ajax_requests: true
        ajax_input_file: 'bar.css'
    

    The form hook is something like

    function tailwind_jit_form_system_theme_settings_alter(&$form, FormStateInterface $form_state, $form_id = NULL) {
      $form['third_party_settings']['tailwind_jit'] = [
        '#type' => 'details',
        '#open' => TRUE,
        '#title' => t('Tailwind CSS Just-in-time compilation'),
        '#tree' => TRUE,
        '#parents' => ['third_party_settings', 'tailwind_jit'],
      ];
      $form['third_party_settings']['tailwind_jit']['compile_html_requests'] = [
        '#type' => 'checkbox',
        '#title' => t('Compile HTML requests'),
        '#default_value' => theme_get_setting('third_party_settings.tailwind_jit.compile_html_requests', $themeToBeConfigured),
      ];
      /* ...more form elements here... */
    }
    

    This does not work correctly, there are two problems:
    1) The schema is not used/validated, the boolean value is still stored as (int) 0 / 1 and not as (bool) true / false
    2) When submitting the form, it saves all my values, but wipes the existing config from shortcut module.

    Reading @berdir's comment, is shortcut a bad example? Should I avoid third party settings for themes at all?

Production build 0.69.0 2024