Issue #2218655 by sun, effulgentsia, jessebeach: Core expects $theme.settings default config file to exist.

8.0.x
Alex Pott 2014-04-09 04:49:22 -04:00
parent 5476dca306
commit 7f00c591b0
14 changed files with 172 additions and 79 deletions

View File

@ -101,12 +101,69 @@ action_configuration_default:
sequence: sequence:
- type: string - type: string
theme_settings_default: theme_settings:
type: mapping type: mapping
mapping: mapping:
shortcut_module_link: favicon:
type: mapping
label: 'Shortcut icon settings'
mapping:
mimetype:
type: string
label: 'MIME type'
path:
type: string
label: 'Path'
url:
type: string
label: 'URL'
use_default:
type: boolean type: boolean
label: 'Shortcut module link' label: 'Use the default shortcut icon supplied by the theme'
features:
type: mapping
label: 'Shortcut icon settings'
mapping:
comment_user_picture:
type: boolean
label: 'User pictures in comments'
comment_user_verification:
type: boolean
label: 'User verification status in comments'
favicon:
type: boolean
label: 'Shortcut icon'
logo:
type: boolean
label: 'Logo'
name:
type: boolean
label: 'Site name'
node_user_picture:
type: boolean
label: 'User pictures in posts'
main_menu:
type: boolean
label: 'Main menu'
secondary_menu:
type: boolean
label: 'Secondary menu'
slogan:
type: boolean
label: 'Site slogan'
logo:
type: mapping
label: 'Shortcut icon settings'
mapping:
path:
type: string
label: 'Logo path'
url:
type: uri
label: 'URL'
use_default:
type: boolean
label: 'Use default'
theme_breakpoints_default: theme_breakpoints_default:
type: sequence type: sequence

View File

@ -12,6 +12,7 @@ use Drupal\Component\Utility\String;
use Drupal\Component\Utility\UrlHelper; use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\Utility\Xss; use Drupal\Component\Utility\Xss;
use Drupal\Core\Config\Config; use Drupal\Core\Config\Config;
use Drupal\Core\Config\StorageException;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
use Drupal\Core\Extension\Extension; use Drupal\Core\Extension\Extension;
use Drupal\Core\Extension\ExtensionNameLengthException; use Drupal\Core\Extension\ExtensionNameLengthException;
@ -862,6 +863,7 @@ function theme_get_setting($setting_name, $theme = NULL) {
else { else {
$theme_keys = array($theme); $theme_keys = array($theme);
} }
// Read hard-coded default settings from the theme info files.
foreach ($theme_keys as $theme_key) { foreach ($theme_keys as $theme_key) {
if (!empty($themes[$theme_key]->info['settings'])) { if (!empty($themes[$theme_key]->info['settings'])) {
$cache[$theme]->merge($themes[$theme_key]->info['settings']); $cache[$theme]->merge($themes[$theme_key]->info['settings']);
@ -873,12 +875,17 @@ function theme_get_setting($setting_name, $theme = NULL) {
$cache[$theme]->merge(\Drupal::config('system.theme.global')->get()); $cache[$theme]->merge(\Drupal::config('system.theme.global')->get());
if ($theme) { if ($theme) {
// Get the saved theme-specific settings from the configuration system. // Retrieve configured theme-specific settings, if any.
$cache[$theme]->merge(\Drupal::config($theme . '.settings')->get()); try {
if ($theme_settings = \Drupal::config($theme . '.settings')->get()) {
$cache[$theme]->merge($theme_settings);
}
}
catch (StorageException $e) {
}
// If the theme does not support a particular feature, override the global // If the theme does not support a particular feature, override the global
// setting and set the value to NULL. // setting and set the value to NULL.
//$supports = $cache[$theme]->get('supports');
if (!empty($theme_object->info['features'])) { if (!empty($theme_object->info['features'])) {
foreach (_system_default_theme_features() as $feature) { foreach (_system_default_theme_features() as $feature) {
if (!in_array($feature, $theme_object->info['features'])) { if (!in_array($feature, $theme_object->info['features'])) {

View File

@ -385,66 +385,5 @@ system.mail:
label: 'Default' label: 'Default'
system.theme.global: system.theme.global:
type: mapping type: theme_settings
label: 'Theme global settings' label: 'Theme global settings'
mapping:
favicon:
type: mapping
label: 'Shortcut icon settings'
mapping:
mimetype:
type: string
label: 'MIME type'
path:
type: string
label: 'Path'
url:
type: string
label: 'URL'
use_default:
type: boolean
label: 'Use the default shortcut icon supplied by the theme'
features:
type: mapping
label: 'Shortcut icon settings'
mapping:
comment_user_picture:
type: boolean
label: 'User pictures in comments'
comment_user_verification:
type: boolean
label: 'User verification status in comments'
favicon:
type: boolean
label: 'Shortcut icon'
logo:
type: boolean
label: 'Logo'
name:
type: boolean
label: 'Site name'
node_user_picture:
type: boolean
label: 'User pictures in posts'
main_menu:
type: boolean
label: 'Main menu'
secondary_menu:
type: boolean
label: 'Secondary menu'
slogan:
type: boolean
label: 'Site slogan'
logo:
type: mapping
label: 'Shortcut icon settings'
mapping:
path:
type: string
label: 'Logo path'
url:
type: uri
label: 'URL'
use_default:
type: boolean
label: 'Use default'

View File

@ -0,0 +1,73 @@
<?php
/**
* @file
* Contains \Drupal\system\Tests\Theme\ThemeSettingsTest.
*/
namespace Drupal\system\Tests\Theme;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\simpletest\DrupalUnitTestBase;
/**
* Tests theme settings functionality.
*/
class ThemeSettingsTest extends DrupalUnitTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('system');
/**
* List of discovered themes.
*
* @var array
*/
protected $availableThemes;
public static function getInfo() {
return array(
'name' => 'Theme settings',
'description' => 'Tests theme settings functionality.',
'group' => 'Theme',
);
}
function setUp() {
parent::setUp();
// Theme settings rely on System module's system.theme.global configuration.
$this->installConfig(array('system'));
if (!isset($this->availableThemes)) {
$discovery = new ExtensionDiscovery();
$this->availableThemes = $discovery->scan('theme');
}
}
/**
* Tests that $theme.settings are imported and used as default theme settings.
*/
function testDefaultConfig() {
$name = 'test_basetheme';
$path = $this->availableThemes[$name]->getPath();
$this->assertTrue(file_exists("$path/config/$name.settings.yml"));
$this->container->get('theme_handler')->enable(array($name));
$this->assertIdentical(theme_get_setting('base', $name), 'only');
}
/**
* Tests that the $theme.settings default config file is optional.
*/
function testNoDefaultConfig() {
$name = 'stark';
$path = $this->availableThemes[$name]->getPath();
$this->assertFalse(file_exists("$path/config/$name.settings.yml"));
$this->container->get('theme_handler')->enable(array($name));
$this->assertNotNull(theme_get_setting('features.favicon', $name));
}
}

View File

@ -0,0 +1,7 @@
test_basetheme.settings:
type: theme_settings
label: 'Test base theme settings'
mapping:
base:
type: string
label: 'Base theme setting'

View File

@ -0,0 +1,3 @@
features:
favicon: false
base: only

View File

@ -35,6 +35,6 @@ regions:
footer_thirdcolumn: 'Footer third column' footer_thirdcolumn: 'Footer third column'
footer_fourthcolumn: 'Footer fourth column' footer_fourthcolumn: 'Footer fourth column'
footer: Footer footer: Footer
# @todo D8: Remove once themes have to be installed.
settings: settings:
shortcut_module_link: '0' shortcut_module_link: false

View File

@ -1 +1,4 @@
# @todo There is no UI yet for configuring this, but the setting is included
# here, because ConfigImportUITest requires a non-empty bartik.settings.yml
# file: https://drupal.org/node/2235901.
shortcut_module_link: false shortcut_module_link: false

View File

@ -1,5 +1,11 @@
# Schema for the configuration files of the Bartik theme. # Schema for the configuration files of the Bartik theme.
bartik.settings: bartik.settings:
type: theme_settings_default type: theme_settings
label: 'Bartik settings' label: 'Bartik settings'
mapping:
# @todo Module-specific settings should be defined by the module:
# https://drupal.org/node/2235901.
shortcut_module_link:
type: boolean
label: 'Shortcut module link'

View File

@ -1,7 +1,7 @@
# Schema for the configuration files of the Seven theme. # Schema for the configuration files of the Seven theme.
seven.settings: seven.settings:
type: theme_settings_default type: theme_settings
label: 'Seven settings' label: 'Seven settings'
seven.breakpoints: seven.breakpoints:

View File

@ -1 +0,0 @@
shortcut_module_link: true

View File

@ -15,9 +15,6 @@ stylesheets-override:
- jquery.ui.theme.css - jquery.ui.theme.css
edit_stylesheets: edit_stylesheets:
- edit.css - edit.css
settings:
# @todo D8: Remove once themes have to be installed.
shortcut_module_link: '1'
regions: regions:
content: Content content: Content
help: Help help: Help
@ -26,3 +23,6 @@ regions:
sidebar_first: 'First sidebar' sidebar_first: 'First sidebar'
regions_hidden: regions_hidden:
- sidebar_first - sidebar_first
settings:
shortcut_module_link: true

View File

@ -1,7 +1,7 @@
# Schema for the configuration files of the Stark theme. # Schema for the configuration files of the Stark theme.
stark.settings: stark.settings:
type: theme_settings_default type: theme_settings
label: 'Stark settings' label: 'Stark settings'
stark.breakpoints: stark.breakpoints:

View File

@ -1 +0,0 @@
shortcut_module_link: false