Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CRM/Upgrade/Incremental/php/SixOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ public function upgrade_6_1_alpha1($rev): void {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);

$this->addTask('Replace Clear Caches & Reset Paths with Clear Caches in Nav Menu', 'updateUpdateConfigBackendNavItem');

$this->addExtensionTask('Enable Riverlea extension', ['riverlea']);
$this->addTask('Freeze "default" theme to Greenwich', 'freezeDefaultThemeToGreenwich');
}

/**
* 'default' is being removed as a valid theme choice.
*
* It has always meant Greenwich, so sites previously on
* "default" change this to an explicit value Greenwich.
*
* @return bool
*/
public static function freezeDefaultThemeToGreenwich() {
$themeSettings = ['theme_backend', 'theme_frontend'];

foreach ($themeSettings as $key) {
$value = \Civi::settings()->get($key);
if ($value === 'default') {
\Civi::settings()->set($key, 'greenwich');
Comment thread
ufundo marked this conversation as resolved.
}
}

return TRUE;
}

/**
Expand Down
47 changes: 25 additions & 22 deletions Civi/Core/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
class Themes extends \Civi\Core\Service\AutoService {

/**
* The "default" theme adapts based on the latest recommendation from civicrm.org
* by switching to DEFAULT_THEME at runtime.
* Disable core CSS.
*/
const DEFAULT_THEME = 'greenwich';
const NO_STYLES = 'none';

/**
* Core CSS only.
*/
const NO_THEME = 'no_theme';

/**
* Fallback is a pseudotheme which can be included in "search_order".
Expand Down Expand Up @@ -68,13 +72,18 @@ public function __construct($cache = NULL) {
*/
public function getActiveThemeKey() {
if ($this->activeThemeKey === NULL) {
// Ambivalent: is it better to use $config->userFrameworkFrontend or $template->get('urlIsPublic')?
$config = \CRM_Core_Config::singleton();
$settingKey = $config->userSystem->isFrontEndPage() ? 'theme_frontend' : 'theme_backend';
$settingKey = \CRM_Utils_System::isFrontEndPage() ? 'theme_frontend' : 'theme_backend';

$themeKey = Civi::settings()->get($settingKey);

// catch for if 'default' value has stuck around. for as long as anyone
// can remember default meant Greenwich
// TODO: remove this catch around 6.12?
if ($themeKey === 'default') {
$themeKey = self::DEFAULT_THEME;
\Civi::log()->debug("Warning: found deprecated value 'default' for '{$settingKey}'. This will be interpreted as Greenwich but this handling may be removed in a future release.");
// fix it for you?
// Civi::settings()->set($settingKey, 'greenwich');
$themeKey = 'greenwich';
}

\CRM_Utils_Hook::activeTheme($themeKey, [
Expand All @@ -83,7 +92,7 @@ public function getActiveThemeKey() {
]);

$themes = $this->getAll();
$this->activeThemeKey = isset($themes[$themeKey]) ? $themeKey : self::DEFAULT_THEME;
$this->activeThemeKey = isset($themes[$themeKey]) ? $themeKey : self::NO_THEME;
}
return $this->activeThemeKey;
}
Expand Down Expand Up @@ -196,27 +205,21 @@ public function resolveUrls($active, $cssExt, $cssFile) {
*/
protected function buildAll() {
$themes = [
'default' => [
'ext' => 'civicrm',
'title' => ts('Automatic'),
'help' => ts('Determine a system default automatically'),
// This is an alias. url_callback, search_order don't matter.
],
'greenwich' => [
'ext' => 'civicrm',
'title' => 'Greenwich',
'help' => ts('CiviCRM 4.x look-and-feel'),
],
'none' => [
self::NO_STYLES => [
'ext' => 'civicrm',
'title' => ts('None (Unstyled)'),
'title' => ts('No Styles'),
'help' => ts('Disable CiviCRM\'s built-in CSS files.'),
'search_order' => ['none', self::FALLBACK_THEME],
'search_order' => [self::NO_STYLES, self::FALLBACK_THEME],
'excludes' => [
"css/civicrm.css",
"css/bootstrap.css",
],
],
self::NO_THEME => [
'ext' => 'civicrm',
'title' => ts('No Theme'),
'search_order' => [self::NO_THEME, self::FALLBACK_THEME],
],
self::FALLBACK_THEME => [
'ext' => 'civicrm',
'title' => 'Fallback (Abstract Base Theme)',
Expand Down
3 changes: 0 additions & 3 deletions ext/greenwich/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
</urls>
<releaseDate>[civicrm.releaseDate]</releaseDate>
<version>[civicrm.version]</version>
<tags>
<tag>mgmt:hidden</tag>
</tags>
<develStage>stable</develStage>
<compatibility>
<ver>[civicrm.majorVersion]</ver>
Expand Down
4 changes: 2 additions & 2 deletions settings/Core.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@
'pseudoconstant' => array(
'callback' => 'call://themes/getAvailable',
),
'default' => 'default',
'default' => 'no_theme',
'add' => '5.16',
'title' => ts('Frontend Theme'),
'is_domain' => 1,
Expand All @@ -1209,7 +1209,7 @@
'pseudoconstant' => array(
'callback' => 'call://themes/getAvailable',
),
'default' => 'default',
'default' => 'no_theme',
'add' => '5.16',
'title' => ts('Backend Theme'),
'is_domain' => 1,
Expand Down
29 changes: 24 additions & 5 deletions tests/phpunit/Civi/Core/ThemesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,23 @@ public function getThemeExamples() {

// --- Library of tests ---

// Use the default theme, Greenwich.
// Use Minetta from Riverlea
// TODO: why is Greenwich enabled here, but Riverlea is not?
// $cases[] = [
// [],
// 'minetta',
// 'Minetta (RiverLea ~Greenwich)',
// [
// 'civicrm-css/civicrm.css' => ["$civicrmBaseUrl/ext/riverlea/core/css/civicrm.css"],
// 'civicrm-css/joomla.css' => ["$civicrmBaseUrl/ext/riverlea/core/css/joomla.css"],
// 'test.extension.uitest-files/foo.css' => ["$civicrmBaseUrl/tests/extensions/test.extension.uitest/files/foo.css"],
// ],
// ];

// Use Greenwich
$cases[] = [
[],
'default',
'greenwich',
'Greenwich',
[
'civicrm-css/civicrm.css' => ["$civicrmBaseUrl/css/civicrm.css"],
Expand All @@ -82,11 +95,11 @@ public function getThemeExamples() {
],
];

// Misconfiguration: liza was previously used but then disappeared. Fallback to default, Greenwich.
// Misconfiguration: liza was previously used but then disappeared. Fallback to default, NO_THEME.
$cases[] = [
$hookJudy,
'liza',
'Greenwich',
'No Theme',
[
'civicrm-css/civicrm.css' => ["$civicrmBaseUrl/css/civicrm.css"],
'civicrm-css/joomla.css' => ["$civicrmBaseUrl/css/joomla.css"],
Expand All @@ -98,7 +111,7 @@ public function getThemeExamples() {
$cases[] = [
$hookJudy,
'none',
'None (Unstyled)',
'No Styles',
[
'civicrm-css/civicrm.css' => [],
'civicrm-css/joomla.css' => ["$civicrmBaseUrl/css/joomla.css"],
Expand Down Expand Up @@ -195,15 +208,20 @@ public static function fakeCallback($themes, $themeKey, $cssExt, $cssFile) {
return $map[$themeKey][$cssExt][$cssFile] ?? Themes::PASSTHRU;
}

/**
* TODO with all these: why do we have greenwich not minetta here?
*/
public function testGetAll(): void {
$all = \Civi::service('themes')->getAll();
$this->assertTrue(isset($all['greenwich']));
// $this->assertTrue(isset($all['minetta']));
$this->assertTrue(isset($all['_fallback_']));
}

public function testGetAvailable(): void {
$all = \Civi::service('themes')->getAvailable();
$this->assertTrue(isset($all['greenwich']));
// $this->assertTrue(isset($all['minetta']));
$this->assertFalse(isset($all['_fallback_']));
}

Expand All @@ -212,6 +230,7 @@ public function testApiOptions(): void {
'field' => 'theme_backend',
]);
$this->assertTrue(isset($result['values']['greenwich']));
// $this->assertTrue(isset($result['values']['minetta']));
$this->assertFalse(isset($result['values']['_fallback_']));
}

Expand Down