summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLauri Eskola2018-05-11 09:54:22 (GMT)
committerLauri Eskola2018-05-11 09:54:22 (GMT)
commit018baee42a9ac79cc5d8cd85bb8ae1a51141637b (patch)
treecd270c9f8580f30451eeee1c284d7090ec4e49fd
parentb187a126def37168e321a8022db00da074278d91 (diff)
Issue #1507896 by b0unty, tuutti, Jeff Burnz, LewisNyman, tameeshb, realityloop, cbanman, umarzaffer, manumilou, mgifford, mducharme, oakulm, lauriii, alexpott, joelpittet, MaskyS, markcarver, xjm: Allow theme developers to add the default logo filename to the theme's .info.yml
-rw-r--r--core/includes/theme.inc3
-rw-r--r--core/lib/Drupal/Core/Theme/ActiveTheme.php19
-rw-r--r--core/lib/Drupal/Core/Theme/ThemeInitialization.php9
-rw-r--r--core/modules/system/tests/themes/test_theme/test_theme.info.yml1
-rw-r--r--core/tests/Drupal/KernelTests/Core/Theme/ThemeSettingsTest.php49
5 files changed, 80 insertions, 1 deletions
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index a6fffa7..30e5aaf 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -343,7 +343,8 @@ function theme_get_setting($setting_name, $theme = NULL) {
// Generate the path to the logo image.
if ($cache[$theme]->get('logo.use_default')) {
- $cache[$theme]->set('logo.url', file_url_transform_relative(file_create_url($theme_object->getPath() . '/logo.svg')));
+ $logo = \Drupal::service('theme.initialization')->getActiveThemeByName($theme)->getLogo();
+ $cache[$theme]->set('logo.url', file_url_transform_relative(file_create_url($logo)));
}
elseif ($logo_path = $cache[$theme]->get('logo.path')) {
$cache[$theme]->set('logo.url', file_url_transform_relative(file_create_url($logo_path)));
diff --git a/core/lib/Drupal/Core/Theme/ActiveTheme.php b/core/lib/Drupal/Core/Theme/ActiveTheme.php
index bb5c766..b7076fb 100644
--- a/core/lib/Drupal/Core/Theme/ActiveTheme.php
+++ b/core/lib/Drupal/Core/Theme/ActiveTheme.php
@@ -20,6 +20,13 @@ class ActiveTheme {
protected $name;
/**
+ * The path to the logo.
+ *
+ * @var string
+ */
+ protected $logo;
+
+ /**
* The path to the theme.
*
* @var string
@@ -100,6 +107,7 @@ class ActiveTheme {
'path' => '',
'engine' => 'twig',
'owner' => 'twig',
+ 'logo' => '',
'stylesheets_remove' => [],
'libraries' => [],
'extension' => 'html.twig',
@@ -110,6 +118,7 @@ class ActiveTheme {
];
$this->name = $values['name'];
+ $this->logo = $values['logo'];
$this->path = $values['path'];
$this->engine = $values['engine'];
$this->owner = $values['owner'];
@@ -204,6 +213,16 @@ class ActiveTheme {
}
/**
+ * Returns the logo provided by the theme.
+ *
+ * @return string
+ * The logo path.
+ */
+ public function getLogo() {
+ return $this->logo;
+ }
+
+ /**
* The regions used by the theme.
*
* @return string[]
diff --git a/core/lib/Drupal/Core/Theme/ThemeInitialization.php b/core/lib/Drupal/Core/Theme/ThemeInitialization.php
index 0067ee8..5d429dd 100644
--- a/core/lib/Drupal/Core/Theme/ThemeInitialization.php
+++ b/core/lib/Drupal/Core/Theme/ThemeInitialization.php
@@ -173,6 +173,15 @@ class ThemeInitialization implements ThemeInitializationInterface {
$values['path'] = $theme_path;
$values['name'] = $theme->getName();
+ // Use the logo declared in this themes info file, otherwise use logo.svg
+ // from the themes root.
+ if (!empty($theme->info['logo'])) {
+ $values['logo'] = $theme->getPath() . '/' . $theme->info['logo'];
+ }
+ else {
+ $values['logo'] = $theme->getPath() . '/logo.svg';
+ }
+
// @todo Remove in Drupal 9.0.x.
$values['stylesheets_remove'] = $this->prepareStylesheetsRemove($theme, $base_themes);
diff --git a/core/modules/system/tests/themes/test_theme/test_theme.info.yml b/core/modules/system/tests/themes/test_theme/test_theme.info.yml
index 1c9745f..b73a45d 100644
--- a/core/modules/system/tests/themes/test_theme/test_theme.info.yml
+++ b/core/modules/system/tests/themes/test_theme/test_theme.info.yml
@@ -14,6 +14,7 @@ description: 'Theme for testing the theme system'
version: VERSION
base theme: classy
core: 8.x
+logo: images/logo2.svg
stylesheets-remove:
- '@system/css/js.module.css'
libraries:
diff --git a/core/tests/Drupal/KernelTests/Core/Theme/ThemeSettingsTest.php b/core/tests/Drupal/KernelTests/Core/Theme/ThemeSettingsTest.php
index a077c25..130df2b 100644
--- a/core/tests/Drupal/KernelTests/Core/Theme/ThemeSettingsTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeSettingsTest.php
@@ -60,4 +60,53 @@ class ThemeSettingsTest extends KernelTestBase {
$this->assertNotNull(theme_get_setting('features.favicon', $name));
}
+ /**
+ * Tests that the default logo config can be overridden.
+ */
+ public function testLogoConfig() {
+ /** @var \Drupal\Core\Extension\ThemeHandler $theme_handler */
+ $theme_handler = $this->container->get('theme_handler');
+ $theme_handler->install(['stark']);
+ $theme = $theme_handler->getTheme('stark');
+
+ // Tests default behaviour.
+ $expected = '/' . $theme->getPath() . '/logo.svg';
+ $this->assertEquals($expected, theme_get_setting('logo.url', 'stark'));
+
+ $config = $this->config('stark.settings');
+ drupal_static_reset('theme_get_setting');
+
+ $values = [
+ 'default_logo' => FALSE,
+ 'logo_path' => 'public://logo_with_scheme.png',
+ ];
+ theme_settings_convert_to_config($values, $config)->save();
+
+ // Tests logo path with scheme.
+ $expected = file_url_transform_relative(file_create_url('public://logo_with_scheme.png'));
+ $this->assertEquals($expected, theme_get_setting('logo.url', 'stark'));
+
+ $values = [
+ 'default_logo' => FALSE,
+ 'logo_path' => $theme->getPath() . '/logo_relative_path.gif',
+ ];
+ theme_settings_convert_to_config($values, $config)->save();
+
+ drupal_static_reset('theme_get_setting');
+
+ // Tests relative path.
+ $expected = '/' . $theme->getPath() . '/logo_relative_path.gif';
+ $this->assertEquals($expected, theme_get_setting('logo.url', 'stark'));
+
+ $theme_handler->install(['test_theme']);
+ $theme_handler->setDefault('test_theme');
+ $theme = $theme_handler->getTheme('test_theme');
+
+ drupal_static_reset('theme_get_setting');
+
+ // Tests logo set in test_theme.info.yml.
+ $expected = '/' . $theme->getPath() . '/images/logo2.svg';
+ $this->assertEquals($expected, theme_get_setting('logo.url', 'test_theme'));
+ }
+
}