Commit 018baee4 authored by lauriii's avatar lauriii

Issue #1507896 by b0unty, tuutti, Jeff Burnz, LewisNyman, tameeshb,...

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
parent b187a126
......@@ -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)));
......
......@@ -19,6 +19,13 @@ class ActiveTheme {
*/
protected $name;
/**
* The path to the logo.
*
* @var string
*/
protected $logo;
/**
* The path to the theme.
*
......@@ -100,6 +107,7 @@ public function __construct(array $values) {
'path' => '',
'engine' => 'twig',
'owner' => 'twig',
'logo' => '',
'stylesheets_remove' => [],
'libraries' => [],
'extension' => 'html.twig',
......@@ -110,6 +118,7 @@ public function __construct(array $values) {
];
$this->name = $values['name'];
$this->logo = $values['logo'];
$this->path = $values['path'];
$this->engine = $values['engine'];
$this->owner = $values['owner'];
......@@ -203,6 +212,16 @@ public function getBaseThemes() {
return $this->baseThemes;
}
/**
* Returns the logo provided by the theme.
*
* @return string
* The logo path.
*/
public function getLogo() {
return $this->logo;
}
/**
* The regions used by the theme.
*
......
......@@ -173,6 +173,15 @@ public function getActiveTheme(Extension $theme, array $base_themes = []) {
$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);
......
......@@ -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:
......
......@@ -60,4 +60,53 @@ public function testNoDefaultConfig() {
$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'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment