Skip to content

Commit

Permalink
Merge pull request getgrav#358 from Sommerregen/feature/better-theme-…
Browse files Browse the repository at this point in the history
…inheritance

Improved theme inheritance to support all kinds of streams
  • Loading branch information
rhukster committed Oct 14, 2015
2 parents 52fcf7c + 2a6437a commit 6c39e43
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions system/src/Grav/Common/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,43 @@ public function configure()
throw new \InvalidArgumentException("Stream '{$type}' could not be initialized.");
}
}

// Load languages after streams has been properly initialized
$this->loadLanguages($this->config);
}

/**
* Load theme configuration.
*
* @param string $name Theme name
* @param Config $config Configuration class
*/
protected function loadConfiguration($name, Config $config)
{
$themeConfig = CompiledYamlFile::instance("themes://{$name}/{$name}" . YAML_EXT)->content();
$config->joinDefaults("themes.{$name}", $themeConfig);
}

/**
* Load theme languages.
*
* @param Config $config Configuration class
*/
protected function loadLanguages(Config $config)
{
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];

if ($config->get('system.languages.translations', true)) {
$languageFiles = array_reverse($locator->findResources("theme://languages" . YAML_EXT));

if ($this->config->get('system.languages.translations', true)) {
$languages = [];
$schemes = array_reverse($config->get("themes.{$name}.streams.schemes.theme.prefixes.", []));
foreach ($schemes as $scheme) {
$languages = array_replace_recursive($languages, CompiledYamlFile::instance("$scheme/languages". YAML_EXT)->content());
foreach ($languageFiles as $language) {
$languages[] = CompiledYamlFile::instance($language)->content();
}

if ($languages) {
$languages = call_user_func_array('array_replace_recursive', $languages);
$config->getLanguages()->mergeRecursive($languages);
}
}
Expand Down

0 comments on commit 6c39e43

Please sign in to comment.