Skip to content
Merged
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
52 changes: 52 additions & 0 deletions Model/Config/Source/AdminThemeList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php declare(strict_types=1);

namespace MageOS\ThemeAdminhtmlSwitcher\Model\Config\Source;

use Magento\Framework\App\Area;
use Magento\Framework\Data\OptionSourceInterface;
use Magento\Framework\View\Design\Theme\ThemeList;

class AdminThemeList implements OptionSourceInterface
{
private ThemeList $themeList;

/**
* AdminThemeList constructor.
*
* @param ThemeList $themeList
*/
public function __construct(ThemeList $themeList)
{
$this->themeList = $themeList;
}

/**
* Get a list of all installed adminhtml themes.
*
* @return array
*/
public function toOptionArray(): array
{
$themes = [];
$this->themeList->addConstraint(ThemeList::CONSTRAINT_AREA, Area::AREA_ADMINHTML);

foreach ($this->themeList->getItems() as $theme) {
$path = $theme->getData('theme_path');

// Replace default admin theme title as 'Magento 2 backend' is not user friendly
$title = $theme->getData('theme_title');
if ($path === 'Magento/backend') {
$title = (string)__('Magento Default');
}

$themes[$title] = [
'label' => $title . ' (' . $path . ')',
'value' => $path
];
}

ksort($themes); // Sort themes alphabetically

return $themes;
}
}
15 changes: 5 additions & 10 deletions Plugin/ThemeAdminhtmlSwitcherPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
namespace MageOS\ThemeAdminhtmlSwitcher\Plugin;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Theme\Model\View\Design;
use Magento\Framework\App\Area;

class ThemeAdminhtmlSwitcherPlugin
{
private $scopeConfig;
private ScopeConfigInterface $scopeConfig;

/**
* ThemeAdminhtmlSwitcherPlugin constructor.
Expand Down Expand Up @@ -40,15 +39,11 @@ public function beforeSetDesignTheme(Design $subject, $themeId = null, $area = n
return [$themeId, $area];
}

$isEnabled = $this->scopeConfig->isSetFlag(
'admin/system_admin_design/enable_theme_adminhtml_m137',
$activeTheme = $this->scopeConfig->getValue(
'admin/system_admin_design/active_theme',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);

if ($isEnabled) {
$themeId = 'MageOS/m137-admin-theme';
}

return [$themeId, $area];

return [$activeTheme ?? $themeId, $area];
}
}
8 changes: 4 additions & 4 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/system_file.xsd">
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="admin">
<group id="system_admin_design" translate="label" type="text" sortOrder="2100" showInDefault="1">
<label>Admin Design</label>
<field id="enable_theme_adminhtml_m137" translate="label" type="select" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Enable M137 Admin Theme</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<field id="active_theme" translate="label" type="select" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Active Admin Theme</label>
<source_model>MageOS\ThemeAdminhtmlSwitcher\Model\Config\Source\AdminThemeList</source_model>
</field>
</group>
</section>
Expand Down
4 changes: 2 additions & 2 deletions etc/config.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/config_file.xsd">
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<admin>
<system_admin_design>
<enable_theme_adminhtml_m137>1</enable_theme_adminhtml_m137>
<active_theme>MageOS/m137-admin-theme</active_theme>
</system_admin_design>
</admin>
</default>
Expand Down
1 change: 1 addition & 0 deletions i18n/en_US.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
"Enable M137 Admin Theme","Enable M137 Admin Theme"
"Admin Design","Admin Design"
"Magento Default","Magento Default"