diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 7580d0b..7bbd4ff 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -325,6 +325,8 @@ function drupal_find_theme_templates($cache, $extension, $path) { * sources: * - the saved values from the global theme settings form * - the saved values from the theme's settings form + * To only retrieve the default global theme setting, an empty string should be + * given for $theme. * * @param $setting_name * The name of the setting to be retrieved. @@ -346,13 +348,13 @@ function theme_get_setting($setting_name, $theme = NULL) { if (empty($cache[$theme])) { // Create a theme settings object. $cache[$theme] = new ThemeSettings($theme); + // Get the global settings from configuration. + $cache[$theme]->setData(\Drupal::config('system.theme.global')->get()); + $themes = \Drupal::service('theme_handler')->listInfo(); if (isset($themes[$theme])) { $theme_object = $themes[$theme]; - // Get the global settings from configuration. - $cache[$theme]->setData(\Drupal::config('system.theme.global')->get()); - // Retrieve configured theme-specific settings, if any. try { if ($theme_settings = \Drupal::config($theme . '.settings')->get()) { diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php index e99397e..17d3a07 100644 --- a/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php @@ -90,8 +90,9 @@ public function __construct(ConfigFactoryInterface $config_factory, StorageInter */ public function installDefaultConfig($type, $name) { $extension_path = drupal_get_path($type, $name); - // If the extension provides configuration schema clear the definitions. - if (is_dir($extension_path . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY)) { + // If the extension provides configuration schema or is a theme clear the + // definitions. + if (is_dir($extension_path . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY) || $type == 'theme') { // Refresh the schema cache if installing default configuration and the // extension has a configuration schema directory. $this->typedConfig->clearCachedDefinitions(); diff --git a/core/modules/config/src/Tests/DefaultConfigTest.php b/core/modules/config/src/Tests/DefaultConfigTest.php index 4880561..99ff07a 100644 --- a/core/modules/config/src/Tests/DefaultConfigTest.php +++ b/core/modules/config/src/Tests/DefaultConfigTest.php @@ -10,7 +10,9 @@ use Drupal\config_test\TestInstallStorage; use Drupal\Core\Config\InstallStorage; use Drupal\Core\Config\TypedConfigManager; +use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\simpletest\KernelTestBase; +use Symfony\Component\DependencyInjection\Reference; /** * Tests that default configuration provided by all modules matches schema. @@ -24,23 +26,46 @@ class DefaultConfigTest extends KernelTestBase { /** * Modules to enable. * + * Enable the system module so that system_config_schema_info_alter() fires. + * + * @var array + */ + public static $modules = array('system', 'config_test'); + + /** + * Themes which provide default configuration and need enabling. + * + * If a theme provides default configuration but does not have a schema + * because it can rely on schemas added by system_config_schema_info_alter() + * then this test needs to enable it. + * * @var array */ - public static $modules = array('config_test'); + protected $themes = ['seven']; + + protected function setUp() { + parent::setUp(); + \Drupal::service('theme_handler')->install($this->themes); + } + + /** + * {@inheritdoc} + */ + public function containerBuild(ContainerBuilder $container) { + parent::containerBuild($container); + $container->register('DefaultConfigTest.schema_storage') + ->setClass('\Drupal\config_test\TestInstallStorage') + ->addArgument(InstallStorage::CONFIG_SCHEMA_DIRECTORY); + + $definition = $container->getDefinition('config.typed'); + $definition->replaceArgument(1, new Reference('DefaultConfigTest.schema_storage')); + } /** * Tests default configuration data type. */ public function testDefaultConfig() { - // Create a typed config manager with access to configuration schema in - // every module, profile and theme. - $typed_config = new TypedConfigManager( - \Drupal::service('config.storage'), - new TestInstallStorage(InstallStorage::CONFIG_SCHEMA_DIRECTORY), - \Drupal::service('cache.discovery'), - \Drupal::service('module_handler') - ); - + $typed_config = \Drupal::service('config.typed'); // Create a configuration storage with access to default configuration in // every module, profile and theme. $default_config_storage = new TestInstallStorage(); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 9334a88..e084a5a 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1344,3 +1344,20 @@ function system_path_insert() { function system_path_delete($path) { \Drupal::service('path.alias_manager')->cacheClear(); } + +/** + * Implements hook_config_schema_info_alter(). + */ +function system_config_schema_info_alter(&$definitions) { + // Provide a default schema for all theme settings files if the theme does + // provide its own schema already.. + foreach (\Drupal::service('theme_handler')->listInfo(TRUE) as $name => $theme) { + $config_name = $name . '.settings'; + if (!isset($definitions[$config_name])) { + $definitions[$config_name] = array( + 'type' => 'theme_settings', + 'label' => $name . ' settings', + ); + } + } +} diff --git a/core/themes/bartik/config/schema/bartik.schema.yml b/core/themes/bartik/config/schema/bartik.schema.yml deleted file mode 100644 index ef355e3..0000000 --- a/core/themes/bartik/config/schema/bartik.schema.yml +++ /dev/null @@ -1,5 +0,0 @@ -# Schema for the configuration files of the Bartik theme. - -bartik.settings: - type: theme_settings - label: 'Bartik settings' diff --git a/core/themes/seven/config/schema/seven.schema.yml b/core/themes/seven/config/schema/seven.schema.yml deleted file mode 100644 index 6d4c86e..0000000 --- a/core/themes/seven/config/schema/seven.schema.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Schema for the configuration files of the Seven theme. - -seven.settings: - type: theme_settings - label: 'Seven settings' - -seven.breakpoints: - type: theme_breakpoints_default - label: 'Seven breakpoints'