-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] display Themes 'Development Mode' setting in system informa… (
#272) * [FEATURE] display Themes 'Development Mode' setting in system information (per root page) * [CLEANUP] add space between concatenation and update comment about signal slot
- Loading branch information
1 parent
7140bf8
commit 670444e
Showing
2 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
<?php | ||
namespace T3kit\themeT3kit\Slot; | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus; | ||
use TYPO3\CMS\Core\Database\ConnectionPool; | ||
use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService; | ||
use TYPO3\CMS\Core\Utility\RootlineUtility; | ||
use TYPO3\CMS\Extbase\Service\TypoScriptService; | ||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; | ||
use TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem; | ||
|
||
/** | ||
* Render custom system info to toolbar item | ||
*/ | ||
class GetSystemInformationSlot | ||
{ | ||
/** | ||
* Signal slot getSystemInformation | ||
* | ||
* @param SystemInformationToolbarItem $sysInfoToolbarItem sysInfoToolbarItem | ||
* | ||
* @return void | ||
*/ | ||
public function getSystemInformation($sysInfoToolbarItem) | ||
{ | ||
$this->getThemeMode($sysInfoToolbarItem); | ||
} | ||
|
||
/** | ||
* Get theme mode to system information | ||
* | ||
* @param SystemInformationToolbarItem $sysInfoToolbarItem sysInfoToolbarItem | ||
* | ||
* @return void | ||
*/ | ||
protected function getThemeMode($sysInfoToolbarItem) | ||
{ | ||
if (ExtensionManagementUtility::isLoaded('themes')) { | ||
|
||
$rootSysTemplates = $this->getRootSysTemplates(); | ||
|
||
if (!empty($rootSysTemplates) && is_array($rootSysTemplates)) { | ||
foreach ($rootSysTemplates as $index => $rootSysTemplate) { | ||
|
||
$themeConfiguration = $this->getThemeConfiguration( | ||
$rootSysTemplate | ||
); | ||
if (!empty($themeConfiguration) | ||
&& is_array($themeConfiguration) | ||
) { | ||
|
||
$inProductionMode | ||
= $themeConfiguration['isDevelopment'] === '0'; | ||
|
||
$themeMode = $inProductionMode | ||
? 'Production' | ||
: 'Development'; | ||
|
||
$themeStatus = $inProductionMode | ||
? InformationStatus::STATUS_OK | ||
: InformationStatus::STATUS_WARNING; | ||
|
||
$sysInfoToolbarItem->addSystemInformation( | ||
'Theme mode [' . $rootSysTemplate['pid'] . ']', | ||
$themeMode, | ||
'sysinfo-application-context', | ||
$themeStatus | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Get root templates | ||
* | ||
* @return array | ||
*/ | ||
protected function getRootSysTemplates() | ||
{ | ||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) | ||
->getQueryBuilderForTable('sys_template'); | ||
$rootSysTemplates = $queryBuilder | ||
->select('*') | ||
->from('sys_template') | ||
->where( | ||
$queryBuilder->expr()->eq( | ||
'root', | ||
$queryBuilder->createNamedParameter(1, \PDO::PARAM_INT) | ||
) | ||
) | ||
->execute() | ||
->fetchAll(); | ||
return $rootSysTemplates; | ||
} | ||
|
||
/** | ||
* Fetch theme configuration constants | ||
* | ||
* @param array $sysTemplate System Template | ||
* | ||
* @return array | ||
*/ | ||
protected function getThemeConfiguration($sysTemplate) | ||
{ | ||
$themeConfiguration = false; | ||
$templateService = GeneralUtility::makeInstance( | ||
ExtendedTemplateService::class | ||
); | ||
$typoScriptService = GeneralUtility::makeInstance( | ||
TypoScriptService::class | ||
); | ||
$templateService->init(); | ||
|
||
$templateUid = $sysTemplate['uid']; | ||
$pageId = $sysTemplate['pid']; | ||
|
||
$rootlineUtility = GeneralUtility::makeInstance( | ||
RootlineUtility::class, | ||
$pageId | ||
); | ||
$rootLine = $rootlineUtility->get(); | ||
|
||
$templateService->runThroughTemplates($rootLine, $templateUid); | ||
$templateService->generateConfig(); | ||
|
||
$themeConfiguration = $templateService | ||
->setup_constants['themes.']['configuration.']; | ||
|
||
if (!empty($themeConfiguration) && is_array($themeConfiguration)) { | ||
$themeConfiguration = $typoScriptService | ||
->convertTypoScriptArrayToPlainArray( | ||
$themeConfiguration | ||
); | ||
} | ||
|
||
return $themeConfiguration; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters