Skip to content

Commit e0df380

Browse files
committed
Configure applied theme via store config, not DI type
1 parent 2a129d2 commit e0df380

6 files changed

Lines changed: 87 additions & 13 deletions

File tree

Config/Source/ThemePathOptions.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Loki\Theme\Config\Source;
4+
5+
use Magento\Framework\Data\OptionSourceInterface;
6+
use Magento\Framework\View\Design\Theme\ThemeList;
7+
use Magento\Framework\View\Design\ThemeInterface;
8+
9+
class ThemePathOptions implements OptionSourceInterface
10+
{
11+
public function __construct(
12+
private readonly ThemeList $themeList,
13+
){
14+
}
15+
16+
public function toOptionArray()
17+
{
18+
$options = [];
19+
foreach ($this->themeList->getItems() as $theme) {
20+
/** @var ThemeInterface $theme */
21+
$options[] = [
22+
'value' => $theme->getThemePath(),
23+
'label' => $theme->getThemePath(),
24+
];
25+
}
26+
27+
return $options;
28+
}
29+
}

Config/ThemeConfig.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,34 @@
33

44
namespace Loki\Theme\Config;
55

6+
use Magento\Framework\App\Config\ScopeConfigInterface;
67
use Magento\Framework\View\DesignInterface;
78

89
class ThemeConfig
910
{
1011
public function __construct(
1112
private readonly DesignInterface $design,
12-
private array $themes = [],
13+
private readonly ScopeConfigInterface $scopeConfig,
1314
) {
1415
}
1516

1617
public function getThemes(): array
1718
{
18-
return $this->themes;
19+
$themeNames = trim($this->scopeConfig->getValue('loki_theme/general/themes'));
20+
if (empty($themeNames)) {
21+
return [];
22+
}
23+
24+
return explode(',', $themeNames);
1925
}
2026

2127
public function modifyCurrentTheme(): bool
2228
{
2329
static $currentTheme = false;
2430
if (false === $currentTheme) {
25-
$currentTheme = $this->design->getDesignTheme()->getFullPath();
31+
$currentTheme = $this->design->getDesignTheme()->getThemePath();
2632
}
2733

28-
return in_array($currentTheme, $this->themes);
34+
return in_array($currentTheme, $this->getThemes());
2935
}
3036
}

etc/acl.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
3+
<acl>
4+
<resources>
5+
<resource id="Magento_Backend::admin">
6+
<resource id="Loki_Theme::configuration" title="Loki Theme configuration" sortOrder="10"/>
7+
</resource>
8+
</resources>
9+
</acl>
10+
</config>

etc/adminhtml/system.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
3+
<system>
4+
<tab id="loki" sortOrder="999" translate="label">
5+
<label>Loki</label>
6+
</tab>
7+
8+
<section id="loki_theme" translate="label" sortOrder="342" showInDefault="1" showInWebsite="1" showInStore="1">
9+
<label>Loki Theme</label>
10+
<tab>loki</tab>
11+
<resource>Loki_Theme::configuration</resource>
12+
<group id="general" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">
13+
<label>Generic settings</label>
14+
<field id="themes"
15+
translate="label"
16+
type="multiselect"
17+
sortOrder="1"
18+
showInDefault="1"
19+
showInWebsite="1"
20+
showInStore="0">
21+
<label>Applied Themes</label>
22+
<tooltip>By applying Loki Theme to a configured theme, its legacy JavaScript will be removed and replaced. Make sure to have tested this properly.</tooltip>
23+
<source_model>Loki\Theme\Config\Source\ThemePathOptions</source_model>
24+
</field>
25+
</group>
26+
</section>
27+
</system>
28+
</config>

etc/config.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" ?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
3+
<default>
4+
<loki_theme>
5+
<general>
6+
<themes>Loki/luma,Loki/base</themes>
7+
</general>
8+
</loki_theme>
9+
</default>
10+
</config>

etc/frontend/di.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
3-
<type name="Loki\Theme\Config\ThemeConfig">
4-
<arguments>
5-
<argument name="themes" xsi:type="array">
6-
<item name="Loki/luma" xsi:type="string">frontend/Loki/luma</item>
7-
<item name="Loki/base" xsi:type="string">frontend/Loki/base</item>
8-
</argument>
9-
</arguments>
10-
</type>
11-
123
<type name="Loki\Theme\Observer\RemoveLegacyHtmlBindings">
134
<arguments>
145
<argument name="patterns" xsi:type="array">

0 commit comments

Comments
 (0)