Skip to content

Commit c3c44bc

Browse files
committed
[FEATURE] Add theme support in site consept
Resolve: #309 Release: 12.1.0
1 parent aa46532 commit c3c44bc

File tree

9 files changed

+175
-33
lines changed

9 files changed

+175
-33
lines changed

Classes/Configuration/ContentElementWizardItems.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function isWizardItemAvailable(int $currentPageId, string $combinedMap
9292
$pageTsConfig = BackendUtility::getPagesTSconfig($currentPageId);
9393
$tvpPageTsConfig = ($pageTsConfig['mod.']['web_txtemplavoilaplusLayout.'] ?? []);
9494
$fcePageTsConfig = ($pageTsConfig['mod.']['wizards.']['newContentElement.']['wizardItems.']['fce.'] ?? []);
95-
if (ItemsProcFunc::isMappingPlaceVisible($tvpPageTsConfig, $combinedMappingIdentifier)) {
95+
if (ItemsProcFunc::isMappingPlaceAllowed($tvpPageTsConfig, $currentPageId, $combinedMappingIdentifier)) {
9696
if (isset($fcePageTsConfig['show']) && $fcePageTsConfig['show']) {
9797
return $fcePageTsConfig['show'] === '*'
9898
|| in_array($wizardLabel, explode(',', $fcePageTsConfig['show']), false)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tvp\TemplaVoilaPlus\Configuration;
6+
7+
/*
8+
* This file is part of the TYPO3 CMS project.
9+
*
10+
* It is free software; you can redistribute it and/or modify it under
11+
* the terms of the GNU General Public License, either version 2
12+
* of the License, or any later version.
13+
*
14+
* For the full copyright and license information, please read the
15+
* LICENSE.txt file that was distributed with this source code.
16+
*
17+
* The TYPO3 project - inspiring people to share!
18+
*/
19+
20+
use Tvp\TemplaVoilaPlus\Service\ConfigurationService;
21+
use TYPO3\CMS\Core\Package\PackageManager;
22+
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
23+
use TYPO3\CMS\Core\Utility\GeneralUtility;
24+
25+
class SiteConfiguration
26+
{
27+
public function getThemeItems(array &$fieldDefinition): void
28+
{
29+
$packageManager = GeneralUtility::makeInstance(PackageManager::class);
30+
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
31+
$placesService = $configurationService->getPlacesService();
32+
33+
$mappingPlaces = $placesService->getAvailablePlacesUsingConfigurationHandlerIdentifier(
34+
\Tvp\TemplaVoilaPlus\Handler\Configuration\MappingConfigurationHandler::$identifier
35+
);
36+
37+
foreach ($mappingPlaces as $mappingPlace) {
38+
$package = $packageManager->getPackage($mappingPlace->getExtensionKey());
39+
40+
$icon = ExtensionManagementUtility::getExtensionIcon(
41+
$packageManager->getPackage($mappingPlace->getExtensionKey())->getPackagePath()
42+
);
43+
44+
$fieldDefinition['items'][$mappingPlace->getIdentifier()] = [
45+
'label' => $mappingPlace->getName(),
46+
'value' => $mappingPlace->getIdentifier(),
47+
'icon' => ($icon ? 'EXT:' . $mappingPlace->getExtensionKey() . '/' . $icon : ''),
48+
// @see https://forge.typo3.org/issues/96461 we cannot manipulate itemGroups
49+
'group' => $package->getPackageMetaData()->getTitle(),
50+
'tempTitles' => [],
51+
];
52+
}
53+
}
54+
}

Classes/Domain/Model/Place.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class Place
3838
/** @var string */
3939
protected $name = '';
4040

41+
protected string $extensionKey;
42+
4143
/** @var string Identifier of the handler to manage coverting between configuration object and configuration array */
4244
protected $configurationHandlerIdentifier = '';
4345

@@ -68,6 +70,7 @@ class Place
6870
public function __construct(
6971
string $identifier,
7072
string $name,
73+
string $extensionKey,
7174
/* @TODO */
7275
$scope,
7376
string $configurationHandlerIdentifier,
@@ -77,6 +80,7 @@ public function __construct(
7780
) {
7881
$this->identifier = $identifier;
7982
$this->name = $name;
83+
$this->extensionKey = $extensionKey;
8084
$this->scope = $scope;
8185
$this->configurationHandlerIdentifier = $configurationHandlerIdentifier;
8286
$this->loadSaveHandlerIdentifier = $loadSaveHandlerIdentifier;
@@ -99,6 +103,11 @@ public function getName(): string
99103
return TemplaVoilaUtility::getLanguageService()->sL($this->name);
100104
}
101105

106+
public function getExtensionKey(): string
107+
{
108+
return $this->extensionKey;
109+
}
110+
102111
public function getConfigurationHandlerIdentifier(): string
103112
{
104113
return $this->configurationHandlerIdentifier;

Classes/Service/ConfigurationService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function getExtensionConfig(): array
101101
public function registerPlace(
102102
string $identifier,
103103
string $name,
104+
string $extension,
104105
/** @TODO */
105106
$scope,
106107
string $configurationHandlerIdentifier,
@@ -118,7 +119,7 @@ public function registerPlace(
118119
// $this->checkHandler $loadSaveHandlerIdentifier
119120

120121
$placesService->registerPlace(
121-
new Place($identifier, $name, $scope, $configurationHandlerIdentifier, $loadSaveHandlerIdentifier, $entryPoint, $indentation)
122+
new Place($identifier, $name, $extension, $scope, $configurationHandlerIdentifier, $loadSaveHandlerIdentifier, $entryPoint, $indentation)
122123
);
123124
}
124125

Classes/Service/ItemsProcFunc.php

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public function mapItems(array $params, object $pObj)
4242
['', ''],
4343
];
4444

45-
$currentPageId = $params['table'] === 'pages' ? $params['row']['uid'] : $params['row']['pid'];
45+
$currentPageId = (int)($params['table'] === 'pages' ? $params['row']['uid'] : $params['row']['pid']);
4646
$pageTsConfig = BackendUtility::getPagesTSconfig($currentPageId);
4747
$tvpPageTsConfig = $pageTsConfig['mod.']['web_txtemplavoilaplusLayout.'];
4848

4949
foreach ($mappingPlaces as $mappingPlace) {
50-
if ($mappingPlace->getScope() === $scope && static::isMappingPlaceVisible($tvpPageTsConfig, $mappingPlace->getIdentifier())) {
50+
if ($mappingPlace->getScope() === $scope && static::isMappingPlaceAllowed($tvpPageTsConfig, $currentPageId, $mappingPlace->getIdentifier())) {
5151
$mappingConfigurations = $mappingPlace->getConfigurations();
5252

5353
foreach ($mappingConfigurations as $mappingConfiguration) {
@@ -90,21 +90,43 @@ protected function getScope(array $params)
9090
*
9191
* @return bool
9292
*/
93-
public static function isMappingPlaceVisible(array $tvpPageTsConfig, string $mappingPlace): bool
93+
public static function isMappingPlaceAllowed(array $tvpPageTsConfig, int $pageId, string $mappingPlaceIdentifier): bool
9494
{
95-
if (isset($tvpPageTsConfig['filterMaps.'])) {
96-
$allowedPlaces = $tvpPageTsConfig['filterMaps.'];
97-
} elseif (isset($tvpPageTsConfig['filterMaps'])) {
98-
$allowedPlaces[] = $tvpPageTsConfig['filterMaps'];
99-
} else {
100-
return true;
95+
$sitesConfiguration = \Tvp\TemplaVoilaPlus\Utility\SitesUtility::getSitesConfiguration($pageId);
96+
$allowedPlaces = $sitesConfiguration['templavoilaplus_allowed_places'] ?? '';
97+
98+
if ($allowedPlaces !== '') {
99+
$allowedPlacesIdentifiers = GeneralUtility::trimExplode(',', $allowedPlaces, true);
100+
101+
$result = self::checkIfAllowed($allowedPlacesIdentifiers, $mappingPlaceIdentifier);
102+
if ($result === false) {
103+
return false;
104+
}
101105
}
102106

103-
foreach ($allowedPlaces as $allowedPlace) {
104-
if (strpos($mappingPlace, $allowedPlace) !== false) {
107+
$allowedPlacesIdentifiers = $tvpPageTsConfig['filterMaps.'] ?? $tvpPageTsConfig['filterMaps'] ?? '';
108+
109+
if ($allowedPlacesIdentifiers !== '') {
110+
if (!is_array($allowedPlacesIdentifiers)) {
111+
$allowedPlacesIdentifiers = [$allowedPlacesIdentifiers];
112+
}
113+
return self::checkIfAllowed($allowedPlacesIdentifiers, $mappingPlaceIdentifier);
114+
}
115+
116+
return true;
117+
}
118+
119+
protected static function checkIfAllowed(array $allowedPlacesIdentifiers, string $mappingPlaceIdentifier): bool
120+
{
121+
/**
122+
* @TODO Maybe use array_find if PHP > 8.4
123+
*/
124+
foreach ($allowedPlacesIdentifiers as $allowedPlaceIdentifier) {
125+
if (strpos($mappingPlaceIdentifier, $allowedPlaceIdentifier) !== false) {
105126
return true;
106127
}
107128
}
129+
108130
return false;
109131
}
110132
}

Classes/Utility/ExtensionUtility.php

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,80 +62,83 @@ public static function handleAllExtensions()
6262
}
6363
// Temnplating TV+
6464
foreach (self::$registeredExtensions as $extensionKey => $path) {
65-
self::loadDataStructurePlaces($path);
66-
self::loadTemplatePlaces($path);
67-
self::loadBackendLayoutPlaces($path);
65+
self::loadDataStructurePlaces($extensionKey, $path);
66+
self::loadTemplatePlaces($extensionKey,$path);
67+
self::loadBackendLayoutPlaces($extensionKey, $path);
6868

6969
// Last one, as it contain references to the other ones
70-
self::loadMappingPlaces($path);
70+
self::loadMappingPlaces($extensionKey, $path);
7171
}
7272
}
7373

7474
/**
7575
* Loads the DataStructurePlaces.php inside the extension path
76-
* @param string $path
7776
* @internal
7877
*/
79-
protected static function loadDataStructurePlaces($path)
78+
protected static function loadDataStructurePlaces(string $extensionKey, string $path): void
8079
{
8180
static::loadPlaces(
81+
$extensionKey,
8282
$path . '/DataStructurePlaces.php',
8383
\Tvp\TemplaVoilaPlus\Handler\Configuration\DataConfigurationHandler::$identifier
8484
);
8585
}
8686

8787
/**
8888
* Loads the MappingPlaces.php inside the extension path
89-
* @param string $path
9089
* @internal
9190
*/
92-
protected static function loadMappingPlaces($path)
91+
protected static function loadMappingPlaces(string $extensionKey, string $path): void
9392
{
9493
static::loadPlaces(
94+
$extensionKey,
9595
$path . '/MappingPlaces.php',
9696
\Tvp\TemplaVoilaPlus\Handler\Configuration\MappingConfigurationHandler::$identifier
9797
);
9898
}
9999

100100
/**
101101
* Loads the TemplatePlaces.php inside the extension path
102-
* @param string $path
103102
* @internal
104103
*/
105-
protected static function loadTemplatePlaces($path)
104+
protected static function loadTemplatePlaces(string $extensionKey, string $path): void
106105
{
107106
static::loadPlaces(
107+
$extensionKey,
108108
$path . '/TemplatePlaces.php',
109109
\Tvp\TemplaVoilaPlus\Handler\Configuration\TemplateConfigurationHandler::$identifier
110110
);
111111
}
112112

113113
/**
114114
* Loads the TemplatePlaces.php inside the extension path
115-
* @param string $path
116115
* @internal
117116
*/
118-
protected static function loadBackendLayoutPlaces($path)
117+
protected static function loadBackendLayoutPlaces(string $extensionKey, string $path): void
119118
{
120119
static::loadPlaces(
120+
$extensionKey,
121121
$path . '/BackendLayoutPlaces.php',
122122
\Tvp\TemplaVoilaPlus\Handler\Configuration\BackendLayoutConfigurationHandler::$identifier
123123
);
124124
}
125125
/**
126126
* Loads the places inside the extension files
127-
* @param string $pathAndFilename
128-
* @param string $defaultConfigurationHandlerIdentifier
129127
* @internal
130128
*/
131-
protected static function loadPlaces(string $pathAndFilename, string $defaultConfigurationHandlerIdentifier)
129+
protected static function loadPlaces(
130+
string $extensionKey,
131+
string $pathAndFilename,
132+
string $defaultConfigurationHandlerIdentifier
133+
): void
132134
{
133135
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
134136
$placeConfigurations = self::getFileContentArray($pathAndFilename);
135137
foreach ($placeConfigurations as $identifier => $placeConfiguration) {
136138
$configurationService->registerPlace(
137139
$identifier,
138140
$placeConfiguration['name'],
141+
$extensionKey,
139142
$placeConfiguration['scope'] ?? '',
140143
$placeConfiguration['configurationHandler'] ?? $defaultConfigurationHandlerIdentifier,
141144
$placeConfiguration['loadSaveHandler'],
@@ -150,7 +153,7 @@ protected static function loadPlaces(string $pathAndFilename, string $defaultCon
150153
* @param string $path
151154
* @internal
152155
*/
153-
protected static function loadExtending($path)
156+
protected static function loadExtending(string $path): void
154157
{
155158
$extending = self::getFileContentArray($path . '/Extending.php');
156159
if (isset($extending['renderHandler'])) {
@@ -173,7 +176,7 @@ protected static function loadExtending($path)
173176
}
174177
}
175178

176-
protected static function registerHandler(array $handlerConfigurations, string $implementorsInterface)
179+
protected static function registerHandler(array $handlerConfigurations, string $implementorsInterface): void
177180
{
178181
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
179182
foreach ($handlerConfigurations as $identifier => $handlerConfiguration) {
@@ -188,10 +191,9 @@ protected static function registerHandler(array $handlerConfigurations, string $
188191

189192
/**
190193
* Loads the Extending.php inside the extension path and registers dataStructureHandler
191-
* @param string $path
192194
* @internal
193195
*/
194-
protected static function loadNewContentElementWizardConfiguration($path)
196+
protected static function loadNewContentElementWizardConfiguration(string $path): void
195197
{
196198
/** @var ConfigurationService */
197199
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
@@ -219,7 +221,7 @@ protected static function loadNewContentElementWizardConfiguration($path)
219221
* @param string $file Absolute path and filename
220222
* @internal
221223
*/
222-
protected static function getFileContentArray($file): array
224+
protected static function getFileContentArray(string $file): array
223225
{
224226
if (is_file($file) && is_readable($file)) {
225227
$content = require $file;

Classes/Utility/SitesUtility.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tvp\TemplaVoilaPlus\Utility;
6+
7+
use TYPO3\CMS\Core\SingletonInterface;
8+
use TYPO3\CMS\Core\Site\SiteFinder;
9+
use TYPO3\CMS\Core\Utility\GeneralUtility;
10+
11+
class SitesUtility implements SingletonInterface
12+
{
13+
private static $configurationCache = [];
14+
15+
public static function getSitesConfiguration(int $pageId): array
16+
{
17+
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
18+
$site = $siteFinder->getSiteByPageId($pageId);
19+
20+
return $site->getConfiguration();
21+
}
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
$GLOBALS['SiteConfiguration']['site']['columns']['templavoilaplus_allowed_places'] = [
4+
'label' => 'LLL:EXT:templavoilaplus/Resources/Private/Language/SiteConfiguration.xlf:site.templavoilaplus_allowed_places.label',
5+
'description' => 'LLL:EXT:templavoilaplus/Resources/Private/Language/SiteConfiguration.xlf:site.templavoilaplus_allowed_places.description',
6+
'config' => [
7+
'type' => 'select',
8+
// Using selectCheckBox as it have bigger and also working icons besides all other options.
9+
'renderType' => 'selectCheckBox',
10+
'appearance' => [
11+
'expandAll' => true,
12+
],
13+
'itemsProcFunc' => \Tvp\TemplaVoilaPlus\Configuration\SiteConfiguration::class . '->getThemeItems',
14+
],
15+
];
16+
17+
// And add it to showitem
18+
$GLOBALS['SiteConfiguration']['site']['types']['0']['showitem'] .= ',--div--;TV+, templavoilaplus_allowed_places';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xliff version="1.2" xmlns:t3="http://typo3.org/schemas/xliff" xmlns="urn:oasis:names:tc:xliff:document:1.2">
3+
<file source-language="en" original="messages" datatype="plaintext" product-name="templavoilaplus" date="2026-02-15T02:33:44+01:00">
4+
<header></header>
5+
<body>
6+
<trans-unit id="site.templavoilaplus_allowed_places.label" resname="site.templavoilaplus_allowed_places.label">
7+
<source>Allowed themes</source>
8+
</trans-unit>
9+
<trans-unit id="site.templavoilaplus_allowed_places.description" resname="site.templavoilaplus_allowed_places.description">
10+
<source>You can define which places from which theme can be used for this site. Leave empty to allow all. You can also use the Page TSconfig mod.web_txtemplavoilaplusLayout.filterMaps for finer grained configuration.</source>
11+
</trans-unit>
12+
</body>
13+
</file>
14+
</xliff>

0 commit comments

Comments
 (0)