Skip to content

Commit

Permalink
[FEATURE] Adding new feature for selecting Theme features/extensions …
Browse files Browse the repository at this point in the history
…in order minimize loaded configuration by using the Theme. More information in Documentation/ExtensionsAndFeaturesInThemes.rst.
  • Loading branch information
tdeuling committed Jul 11, 2018
1 parent a1e0200 commit e193531
Show file tree
Hide file tree
Showing 17 changed files with 379 additions and 36 deletions.
9 changes: 7 additions & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## Themes Change-Log
# Themes Change-Log

## 2018-07-11 Release of version 8.7.2

### 2018-06-11 Thomas Deuling <[email protected]>

* [FEATURE] Adding new feature for selecting Theme features/extensions in order minimize loaded configuration by using the Theme. More information in Documentation/ExtensionsAndFeaturesInThemes.rst.

### 2015-08-02 Thomas Deuling <[email protected]>

* [TASK] Adding new content element wizard for buttoncontent
* [TASK] Adding new content element wizard for buttoncontent
102 changes: 95 additions & 7 deletions Classes/Domain/Model/AbstractTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;

/**
* Class AbstractTheme.
*
* @todo get rid of getExtensionname, use EXT:extname as theme name to avoid conflicts in the database
*/
class AbstractTheme extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
class AbstractTheme extends AbstractEntity
{
/**
* @var string
Expand Down Expand Up @@ -67,6 +70,7 @@ class AbstractTheme extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
/**
* Constructs a new Theme.
*
* @param string $extensionName
* @api
*/
public function __construct($extensionName)
Expand Down Expand Up @@ -107,7 +111,11 @@ public function getDescription()
*/
public function getPreviewImage()
{
return $this->previewImage;
// We need to use a real image file path, because in case of using a file
// reference, a non admin backend user might not have access to the storage!
$previewImage = GeneralUtility::getFileAbsFileName($this->previewImage);
$previewImage = PathUtility::getAbsoluteWebPath($previewImage);
return $previewImage;
}

/**
Expand Down Expand Up @@ -162,7 +170,7 @@ public function getVersion()
}

/**
* @todo missing docblock
* @return array
*/
public function getAuthor()
{
Expand All @@ -186,10 +194,15 @@ public function getManualUrl()
*/
public function getTypoScriptConfig()
{
if (file_exists($this->getTypoScriptConfigAbsPath()) && is_file($this->getTypoScriptConfigAbsPath())) {
return file_get_contents($this->getTypoScriptConfigAbsPath());
$typoScriptConfig = '';
$typoScriptConfigAbsPath = $this->getTypoScriptConfigAbsPath();
if (file_exists($typoScriptConfigAbsPath) && is_file($typoScriptConfigAbsPath)) {
$typoScriptConfig = file_get_contents($typoScriptConfigAbsPath);
}
return '';



return $typoScriptConfig;
}

/**
Expand Down Expand Up @@ -235,10 +248,12 @@ public function getRelativePath()
*
* @param array $params Array of parameters from the parent class. Includes idList, templateId, pid, and row.
* @param \TYPO3\CMS\Core\TypoScript\TemplateService $pObj Reference back to parent object, t3lib_tstemplate or one of its subclasses.
* @param array $extensions Array of additional TypoScript for extensions
* @param array $features Array of additional TypoScript for features
*
* @return void
*/
public function addTypoScriptForFe(&$params, \TYPO3\CMS\Core\TypoScript\TemplateService &$pObj)
public function addTypoScriptForFe(&$params, TemplateService &$pObj, $extensions=[], $features=[])
{
// @codingStandardsIgnoreStart
$themeItem = [
Expand All @@ -261,6 +276,79 @@ public function addTypoScriptForFe(&$params, \TYPO3\CMS\Core\TypoScript\Template
'ext_themes'.str_replace('_', '', $this->getExtensionName()),
$params['templateId']
);
//
// Additional TypoScript for extensions
if(count($extensions) > 0) {
foreach($extensions as $extension) {
$themeItem = $this->getTypoScriptDataForProcessing($extension, 'extension');
$pObj->processTemplate(
$themeItem,
$params['idList'].',ext_theme'.str_replace('_', '', $this->getExtensionName()),
$params['pid'], 'ext_theme'.str_replace('_', '', $this->getExtensionName()),
$params['templateId']
);
}
}
//
// Additional TypoScript for features
if(count($features) > 0) {
foreach($features as $feature) {
$themeItem = $this->getTypoScriptDataForProcessing($feature, 'feature');
$pObj->processTemplate(
$themeItem,
$params['idList'].',ext_theme'.str_replace('_', '', $this->getExtensionName()),
$params['pid'], 'ext_theme'.str_replace('_', '', $this->getExtensionName()),
$params['templateId']
);
}
}
}

/**
* @param $key string Key of the Extension or Feature
* @param $type string Typ can be either extension or feature.
* @return array
*/
protected function getTypoScriptDataForProcessing($key, $type='extension') {
$relPath = '';
$keyParts = explode('_', $key);
$extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($keyParts[0]);
$extensionPath = ExtensionManagementUtility::extPath($extensionKey);
if($type === 'feature') {
$relPath = $extensionPath . 'Configuration/TypoScript/Features/' . $keyParts[1] . '/';
}
else if($type === 'extension') {
$relPath = $extensionPath . 'Resources/Private/Extensions/' . $keyParts[1] . '/TypoScript/';
}
$themeItem = [
'constants' => '',
'config' => '',
'include_static' => '',
'include_static_file' => '',
'title' => 'themes:' . $this->getExtensionName() . ':' . $relPath,
'uid' => md5($this->getExtensionName() . ':' . $relPath),
];
$setupFile = GeneralUtility::getFileAbsFileName($relPath . 'setup.txt');
if(file_exists($setupFile)) {
$themeItem['config'] = file_get_contents($setupFile);
}
else {
$setupFile = GeneralUtility::getFileAbsFileName($relPath . 'setup.typoscript');
if(file_exists($setupFile)) {
$themeItem['config'] = file_get_contents($setupFile);
}
}
$constantsFile = GeneralUtility::getFileAbsFileName($relPath . 'constants.txt');
if(file_exists($constantsFile)) {
$themeItem['constants'] = file_get_contents($constantsFile);
}
else {
$constantsFile = GeneralUtility::getFileAbsFileName($relPath . 'constants.typoscript');
if(file_exists($constantsFile)) {
$themeItem['constants'] = file_get_contents($constantsFile);
}
}
return $themeItem;
}

/**
Expand Down
49 changes: 43 additions & 6 deletions Classes/Domain/Model/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Core\TypoScript\TemplateService;

/**
* Class Theme.
Expand All @@ -15,6 +17,8 @@ class Theme extends AbstractTheme
/**
* Constructs a new Theme.
*
* @param $extensionName
* @throws \Exception
* @api
*/
public function __construct($extensionName)
Expand Down Expand Up @@ -99,11 +103,15 @@ protected function importExtEmConf()
public function getAllPreviewImages()
{
$buffer = $this->metaInformation['screenshots'];
$buffer[] = [
'file' => $this->getPreviewImage(),
'caption' => '',
];

if(count($buffer) > 0) {
foreach($buffer as $key => $image) {
// We need to use a real image file path, because in case of using a file
// reference, a non admin backend user might not have access to the storage!
$previewImage = GeneralUtility::getFileAbsFileName($image['file']);
$previewImage = PathUtility::getAbsoluteWebPath($previewImage);
$buffer[$key]['file'] = $previewImage;
}
}
return $buffer;
}

Expand Down Expand Up @@ -138,10 +146,12 @@ public function getRelativePath()
*
* @param array $params Array of parameters from the parent class. Includes idList, templateId, pid, and row.
* @param object $pObj Reference back to parent object, t3lib_tstemplate or one of its subclasses.
* @param array $extensions Array of additional TypoScript for extensions
* @param array $features Array of additional TypoScript for features
*
* @return void
*/
public function addTypoScriptForFe(&$params, \TYPO3\CMS\Core\TypoScript\TemplateService &$pObj)
public function addTypoScriptForFe(&$params, TemplateService &$pObj, $extensions=[], $features=[])
{
// @codingStandardsIgnoreStart
$themeItem = [
Expand All @@ -166,5 +176,32 @@ public function addTypoScriptForFe(&$params, \TYPO3\CMS\Core\TypoScript\Template
$params['pid'], 'ext_theme'.str_replace('_', '', $this->getExtensionName()),
$params['templateId']
);
//
// Additional TypoScript for extensions
if(count($extensions) > 0) {
foreach($extensions as $extension) {
$themeItem = $this->getTypoScriptDataForProcessing($extension, 'extension');
$pObj->processTemplate(
$themeItem,
$params['idList'].',ext_theme'.str_replace('_', '', $this->getExtensionName()),
$params['pid'], 'ext_theme'.str_replace('_', '', $this->getExtensionName()),
$params['templateId']
);
}
}
//
// Additional TypoScript for features
if(count($features) > 0) {
foreach($features as $feature) {
$themeItem = $this->getTypoScriptDataForProcessing($feature, 'feature');
$pObj->processTemplate(
$themeItem,
$params['idList'].',ext_theme'.str_replace('_', '', $this->getExtensionName()),
$params['pid'], 'ext_theme'.str_replace('_', '', $this->getExtensionName()),
$params['templateId']
);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\TypoScript\TemplateService;

/**
* Class T3libTstemplateIncludeStaticTypoScriptSourcesAtEndHook.
Expand All @@ -22,12 +23,11 @@ class T3libTstemplateIncludeStaticTypoScriptSourcesAtEndHook
*
* @return void
*/
public static function main(&$params, \TYPO3\CMS\Core\TypoScript\TemplateService &$pObj)
public static function main(&$params, TemplateService &$pObj)
{
$idList = $params['idList'];
$templateId = $params['templateId'];
$pid = $params['pid'];
$row = $params['row'];
if ($templateId === $idList) {
/** @var \TYPO3\CMS\Core\Database\Query\QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
Expand Down Expand Up @@ -64,7 +64,9 @@ public static function main(&$params, \TYPO3\CMS\Core\TypoScript\TemplateService
$theme = $themeRepository->findByUid($tRow['tx_themes_skin']);
}
if ($theme !== null) {
$theme->addTypoScriptForFe($params, $pObj);
$themeExtensions = GeneralUtility::trimExplode(',', $tRow['tx_themes_extensions'], true);
$themeFeatures = GeneralUtility::trimExplode(',', $tRow['tx_themes_features'], true);
$theme->addTypoScriptForFe($params, $pObj, $themeExtensions, $themeFeatures);
}
// @todo add hook to inject template overlays, e.g. for previewed constants before save ...
// Call hook for possible manipulation of current skin. constants
Expand Down
Loading

0 comments on commit e193531

Please sign in to comment.