diff --git a/ChangeLog.md b/ChangeLog.md index 868f108c..72f904ba 100755 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -19,8 +19,8 @@ * [BREAKING] Remove constant view helper including cache logic - please pass your constants by plugin settings for achieving better performance. * [TASK] Remove t3jquery.txt configuration. * [TASK] Remove of the moduleBodyPostProcess Hook which is no longer available in TYPO3 9.5. - - +* [TASK] Remove pageTsBackendLayoutDataProvider because it's part of the code since TYPO3 7.6. +* [TASK] Migrate the language TypoScript constants to site configuration settings. ### 2018-10-29 Thomas Deuling diff --git a/Classes/Controller/EditorController.php b/Classes/Controller/EditorController.php index a0593687..7f4f13fe 100755 --- a/Classes/Controller/EditorController.php +++ b/Classes/Controller/EditorController.php @@ -44,14 +44,15 @@ use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; -use TYPO3\CMS\Extbase\Utility\DebuggerUtility; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; +use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; /** * Class EditorController. */ class EditorController extends ActionController { + /** * @var string Key of the extension this controller belongs to */ @@ -192,20 +193,23 @@ protected function createButtons() * *@return void */ - protected function createMenu() + protected function createMenu(): void { /** @var UriBuilder $uriBuilder */ $uriBuilder = $this->objectManager->get(UriBuilder::class); $uriBuilder->setRequest($this->request); - $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu(); $menu->setIdentifier('themes'); - $actions = [ - ['action' => 'index', 'label' => LocalizationUtility::translate('setConstants', $this->extensionName)], - ['action' => 'showTheme', 'label' => LocalizationUtility::translate('setTheme', $this->extensionName)] + [ + 'action' => 'index', + 'label' => LocalizationUtility::translate('setConstants', $this->extensionName) + ], + [ + 'action' => 'showTheme', + 'label' => LocalizationUtility::translate('setTheme', $this->extensionName) + ], ]; - foreach ($actions as $action) { $item = $menu->makeMenuItem() ->setTitle($action['label']) @@ -213,24 +217,21 @@ protected function createMenu() ->setActive($this->request->getControllerActionName() === $action['action']); $menu->addMenuItem($item); } - $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu); } - protected function getExtensionConfiguration(string $extensionKey) { - $configuration = []; - if((int)TYPO3_version === 9) { - // Attention: Full namespace required! - $configuration = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)->get($extensionKey); - } - if((int)TYPO3_version === 8) { - if(isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey])) { - $configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$extensionKey]); - // Attention: Full namespace required! - $typoScriptService = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Service\TypoScriptService::class); - $configuration = $typoScriptService->convertTypoScriptArrayToPlainArray($configuration); - } - } + /** + * @param string $extensionKey + * @return array + * @throws \TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException + * @throws \TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException + */ + protected function getExtensionConfiguration(string $extensionKey): array + { + /** @var ExtensionConfiguration $extensionConfiguration */ + $extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class); + /** @var array $configuration */ + $configuration = $extensionConfiguration->get($extensionKey); return $configuration; } @@ -304,13 +305,10 @@ public function indexAction() $nearestPageWithTheme = 0; } - $this->view->assignMultiple( - [ - 'pid' => $this->id, - 'nearestPageWithTheme' => $nearestPageWithTheme, - 'themeIsSelectable' => CheckPageUtility::hasThemeableSysTemplateRecord($this->id), - ] - ); + + $this->view->assign('pid', $this->id); + $this->view->assign('nearestPageWithTheme', $nearestPageWithTheme); + $this->view->assign('themeIsSelectable', CheckPageUtility::hasThemeableSysTemplateRecord($this->id)); } /** diff --git a/Classes/Controller/ThemeController.php b/Classes/Controller/ThemeController.php index 3db2b514..074c9625 100755 --- a/Classes/Controller/ThemeController.php +++ b/Classes/Controller/ThemeController.php @@ -91,17 +91,6 @@ public function injectPageRepository(PageRepository $pageRepository) $this->pageRepository = $pageRepository; } - /** - * @return void - */ - public function initializeAction() - { - /** - * @todo solve by inject method?! - */ - //$this->themeRepository = new \KayStrobach\Themes\Domain\Repository\ThemeRepository(); - } - /** * renders the given theme. * @@ -109,7 +98,7 @@ public function initializeAction() */ public function indexAction() { - $this->templateName = $this->evaluateTypoScript('plugin.tx_themes.settings.templateName'); + $this->templateName = $this->evaluateTypoScript('plugin.tx_themes.view.templateName'); $templateFile = $this->getTemplateFile(); if ($templateFile !== null) { $this->view->setTemplatePathAndFilename($templateFile); @@ -127,7 +116,8 @@ public function indexAction() $pageArray['icon'] = $setup['lib.']['icons.']['cssMap.'][$pageArray['tx_themes_icon']]; } // Get settings, because they aren't available - $configuration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, 'Themes'); + $configurationType = ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK; + $configuration = $this->configurationManager->getConfiguration($configurationType, 'Themes'); unset($configuration['settings']['templateName']); $this->view->assign('settings', $configuration['settings']); $this->view->assign('page', $pageArray); @@ -157,15 +147,12 @@ protected function evaluateTypoScript($path) $vh->setRenderChildrenClosure(function () { return ''; }); - if (version_compare(TYPO3_version, '8.0', '<')) { - return $vh->render($path); - } else { - $vh->setArguments(['typoscriptObjectPath' => $path]); - /** @var \TYPO3\CMS\Fluid\Core\Rendering\RenderingContext $renderingContext */ - $renderingContext = GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContext::class); - $vh->setRenderingContext($renderingContext); - return $vh->render(); - } + + $vh->setArguments(['typoscriptObjectPath' => $path]); + /** @var \TYPO3\CMS\Fluid\Core\Rendering\RenderingContext $renderingContext */ + $renderingContext = GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContext::class); + $vh->setRenderingContext($renderingContext); + return $vh->render(); } /** diff --git a/Classes/Domain/Model/AbstractTheme.php b/Classes/Domain/Model/AbstractTheme.php index 07282409..93c8ba33 100755 --- a/Classes/Domain/Model/AbstractTheme.php +++ b/Classes/Domain/Model/AbstractTheme.php @@ -28,12 +28,15 @@ ***************************************************************/ use KayStrobach\Themes\Utilities\ApplicationContext; +use TYPO3\CMS\Core\Site\Entity\Site; +use TYPO3\CMS\Core\Utility\ArrayUtility; 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; +use TYPO3\CMS\Extbase\Utility\DebuggerUtility; /** * Class AbstractTheme. @@ -136,16 +139,16 @@ public function getDescription() */ public function getPreviewImage() { - // 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); - // Since 8.7.x we need to prefix with EXT: - $replacement = '/typo3conf/ext/'; - if (substr($previewImage, 0, strlen($replacement)) === $replacement) { - $previewImage = str_replace('/typo3conf/ext/', 'EXT:', $previewImage); - } - return $previewImage; + return $this->previewImage; + } + + /** + * Check if the previewImage exists. + * @return bool + */ + public function getPreviewImageExists(): bool + { + return file_exists(GeneralUtility::getFileAbsFileName($this->previewImage)); } /** @@ -379,46 +382,38 @@ protected function getTypoScriptDataForProcessing($key, $type = 'extension') */ public function getTypoScriptForLanguage(&$params, &$pObj) { - - /** - * @todo refactor - */ - - /** @var \TYPO3\CMS\Core\Database\Query\QueryBuilder $queryBuilder */ - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) - ->getQueryBuilderForTable('sys_language'); - $queryBuilder->select('sys_language.*', 'static_languages.lg_name_local', 'static_languages.lg_name_en', 'static_languages.lg_collate_locale') - ->from('sys_language') - ->from('static_languages') - ->where( - $queryBuilder->expr()->eq( - 'sys_language.static_lang_isocode', 'static_languages.uid' - ) - ); - /** @var \Doctrine\DBAL\Driver\Statement $statement */ - $languages = $queryBuilder->execute(); $outputBuffer = ''; - $languageUids = []; $key = 'themes.languages'; - if ($languages->rowCount() > 0) { - while ($language = $languages->fetch()) { - $languageUids[] = $language['uid']; - $buffer = '[globalVar = GP:L=' . $language['uid'] . ']' . LF; - $buffer .= $key . '.current {' . LF; - $buffer .= ' uid = ' . $language['uid'] . LF; - $buffer .= ' label = ' . $language['title'] . LF; - $buffer .= ' labelLocalized = ' . $language['lg_name_local'] . LF; - $buffer .= ' labelEnglish = ' . $language['lg_name_en'] . LF; - $buffer .= ' flag = ' . $language['flag'] . LF; - $buffer .= ' isoCode = ' . $language['lg_collate_locale'] . LF; - $buffer .= ' isoCodeShort = ' . array_shift(explode('_', $language['lg_collate_locale'])) . LF; - $buffer .= ' isoCodeHtml = ' . str_replace('_', '-', $language['lg_collate_locale']) . LF; - $buffer .= '} ' . LF; - $buffer .= '[global]' . LF; - $outputBuffer .= $buffer; + $request = $GLOBALS['TYPO3_REQUEST'] ?? null; + $site = $request ? $request->getAttribute('site') : null; + if ($site instanceof Site) { + $languages = ArrayUtility::getValueByPath($site->getConfiguration(), 'languages', '.'); + if (count($languages) > 0) { + $languageUids = []; + foreach ($languages as $key => $language) { + $languageUid = (int)$language['languageId']; + $languageUids[] = $languageUid; + $buffer = '[globalVar = GP:L=' . $languageUid . ']' . LF; + $buffer .= $key . '.current {' . LF; + $buffer .= ' uid = ' . $languageUid . LF; + $buffer .= ' label = ' . $language['title'] . LF; + $buffer .= ' labelLocalized = ' . $language['navigationTitle'] . LF; + $buffer .= ' labelEnglish = ' . $language['navigationTitle'] . LF; + $buffer .= ' flag = ' . $language['flag'] . LF; + $buffer .= ' isoCode = ' . $language['locale'] . LF; + $buffer .= ' isoCodeShort = ' . $language['iso-639-1'] . LF; + $buffer .= ' isoCodeHtml = ' . $language['hreflang'] . LF; + $buffer .= '} ' . LF; + $buffer .= '[global]' . LF; + $outputBuffer .= $buffer; + } + $outputBuffer .= $key . '.available=' . implode(',', $languageUids) . LF; } - $outputBuffer .= $key . '.available=' . implode(',', $languageUids) . LF; - } else { + else { + $outputBuffer .= $key . '.available=' . LF; + } + } + else { $outputBuffer .= $key . '.available=' . LF; } return $outputBuffer; diff --git a/Classes/Domain/Model/Theme.php b/Classes/Domain/Model/Theme.php index 66b6a559..c9da0650 100755 --- a/Classes/Domain/Model/Theme.php +++ b/Classes/Domain/Model/Theme.php @@ -66,16 +66,8 @@ public function __construct($extensionName) } $yamlFile = ExtensionManagementUtility::extPath($this->getExtensionName()) . 'Meta/theme.yaml'; if (file_exists($yamlFile)) { - if (version_compare(TYPO3_version, '8.7', '<')) { - if (class_exists('\Symfony\Component\Yaml\Yaml')) { - $this->metaInformation = \Symfony\Component\Yaml\Yaml::parse($yamlFile); - } else { - throw new \Exception('No Yaml Parser!'); - } - } else { - $yamlSource = GeneralUtility::makeInstance(YamlSource::class); - $this->metaInformation = $yamlSource->load(array($yamlFile)); - } + $yamlSource = GeneralUtility::makeInstance(YamlSource::class); + $this->metaInformation = $yamlSource->load(array($yamlFile)); } else { throw new \Exception('No Yaml meta information found!'); } diff --git a/Classes/Domain/Repository/ThemeRepository.php b/Classes/Domain/Repository/ThemeRepository.php index f4d80417..bb00161d 100755 --- a/Classes/Domain/Repository/ThemeRepository.php +++ b/Classes/Domain/Repository/ThemeRepository.php @@ -30,6 +30,7 @@ use KayStrobach\Themes\Domain\Model\AbstractTheme; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\SingletonInterface; +use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Object\Exception; use TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface; @@ -50,38 +51,15 @@ class ThemeRepository implements RepositoryInterface, SingletonInterface protected $addedObjects = []; /** - * creates the repo. - * * @return void - * - * @todo missing detailed description */ public function __construct() { - /** - * @var \TYPO3\CMS\Core\Log\LogManager - */ - $logger = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Log\\LogManager'); - - // hook to recognize themes, this is the magic point, why it's possible to support so many theme formats and types :D - if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Tx_Themes_Domain_Repository_ThemeRepository']['init'])) { - if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Tx_Themes_Domain_Repository_ThemeRepository']['init'])) { - $hookParameters = []; - foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Tx_Themes_Domain_Repository_ThemeRepository']['init'] as $hookFunction) { - $logger->getLogger()->warning( - 'Theme loader found '.$hookFunction. - ' - sadly this loader uses the old hook, please fix this, should be KayStrobach\\Themes\\Domain\\Repository\\ThemeRepository nowThem' - ); - GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this); - } - } - } - + // Hook to recognize themes, this is the magic point, why it's possible to support so many theme formats and types. if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['KayStrobach\\Themes\\Domain\\Repository\\ThemeRepository']['init'])) { if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['KayStrobach\\Themes\\Domain\\Repository\\ThemeRepository']['init'])) { $hookParameters = []; foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['KayStrobach\\Themes\\Domain\\Repository\\ThemeRepository']['init'] as $hookFunction) { - $logger->getLogger()->warning('Theme loader found '.$hookFunction); GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this); } } @@ -92,9 +70,7 @@ public function __construct() * Adds an object to this repository. * * @param \KayStrobach\Themes\Domain\Model\AbstractTheme $object The object to add - * * @return void - * * @api */ public function add($object) @@ -106,54 +82,44 @@ public function add($object) * Removes an object from this repository. * * @param \KayStrobach\Themes\Domain\Model\AbstractTheme $object The object to remove - * * @throws \TYPO3\CMS\Extbase\Object\Exception - * * @return void - * * @api */ public function remove($object) { - throw new Exception('The method '.__FUNCTION__.' is not implemented'); + throw new Exception('The method ' . __FUNCTION__ . ' is not implemented'); } /** * Replaces an object by another. * * @param AbstractTheme $existingObject The existing object - * @param AbstractTheme $newObject The new object - * + * @param AbstractTheme $newObject The new object * @throws \TYPO3\CMS\Extbase\Object\Exception - * * @return void - * * @api */ public function replace($existingObject, $newObject) { - throw new Exception('The method '.__FUNCTION__.' is not implemented'); + throw new Exception('The method ' . __FUNCTION__ . ' is not implemented'); } /** * Replaces an existing object with the same identifier by the given object. * * @param AbstractTheme $modifiedObject The modified object - * * @throws \TYPO3\CMS\Extbase\Object\Exception - * * @return void - * * @api */ public function update($modifiedObject) { - throw new Exception('The method '.__FUNCTION__.' is not implemented'); + throw new Exception('The method ' . __FUNCTION__ . ' is not implemented'); } /** - * Returns all objects of this repository add()ed but not yet persisted to - * the storage layer. + * Returns all objects of this repository add()ed but not yet persisted to the storage layer. * * @return array An array of objects */ @@ -163,23 +129,20 @@ public function getAddedObjects() } /** - * Returns an array with objects remove()d from the repository that - * had been persisted to the storage layer before. + * Returns an array with objects remove()d from the repository that had been persisted to the storage layer before. * * @throws \TYPO3\CMS\Extbase\Object\Exception - * * @return void */ public function getRemovedObjects() { - throw new Exception('The method '.__FUNCTION__.' is not implemented'); + throw new Exception('The method ' . __FUNCTION__ . ' is not implemented'); } /** * Returns all objects of this repository. * * @return array An array of objects, empty if no objects found - * * @api */ public function findAll() @@ -191,7 +154,6 @@ public function findAll() * Returns the total number objects of this repository. * * @return int The object count - * * @api */ public function countAll() @@ -200,11 +162,9 @@ public function countAll() } /** - * Removes all objects of this repository as if remove() was called for - * all of them. + * Removes all objects of this repository as if remove() was called for all of them. * * @return void - * * @api */ public function removeAll() @@ -216,9 +176,7 @@ public function removeAll() * Finds an object matching the given identifier. * * @param int $uid The identifier of the object to find - * * @return AbstractTheme The matching object if found, otherwise NULL - * * @api */ public function findByUid($uid) @@ -230,7 +188,6 @@ public function findByUid($uid) /** * @param mixed $uid - * * @return AbstractTheme */ public function findByIdentifier($uid) @@ -240,28 +197,24 @@ public function findByIdentifier($uid) /** * @param int $pid id of the Page - * * @return mixed */ public function findByPageId($pid) { - $template = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService'); + $template = GeneralUtility::makeInstance(ExtendedTemplateService::class); $template->tt_track = 0; $template->init(); $templateRow = $template->ext_getFirstTemplate($pid); - return $this->findByUid($templateRow['tx_themes_skin']); } /** * @param int $pid - * * @return \KayStrobach\Themes\Domain\Model\Theme */ public function findByPageOrRootline($pid) { $rootline = BackendUtility::BEgetRootLine($pid); - foreach ($rootline as $page) { $theme = $this->findByPageId($page['uid']); if ($theme !== null) { @@ -279,45 +232,38 @@ public function findByPageOrRootline($pid) * ). * * @param array $defaultOrderings The property names to order by - * * @throws \TYPO3\CMS\Extbase\Object\Exception - * * @return void - * * @api */ public function setDefaultOrderings(array $defaultOrderings) { - throw new Exception('The method '.__FUNCTION__.' is not implemented'); + throw new Exception('The method ' . __FUNCTION__ . ' is not implemented'); } /** * Sets the default query settings to be used in this repository. * * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings The query settings to be used by default - * * @throws \TYPO3\CMS\Extbase\Object\Exception - * * @return void - * * @api */ public function setDefaultQuerySettings(QuerySettingsInterface $defaultQuerySettings) { - throw new Exception('The method '.__FUNCTION__.' is not implemented'); + throw new Exception('The method ' . __FUNCTION__ . ' is not implemented'); } /** * Returns a query for objects of this repository. * * @throws \TYPO3\CMS\Extbase\Object\Exception - * * @return void - * * @api */ public function createQuery() { - throw new Exception('The method '.__FUNCTION__.' is not implemented'); + throw new Exception('The method ' . __FUNCTION__ . ' is not implemented'); } + } diff --git a/Classes/Hooks/PageRenderer.php b/Classes/Hooks/PageRenderer.php index 5fc2ed48..a985221a 100755 --- a/Classes/Hooks/PageRenderer.php +++ b/Classes/Hooks/PageRenderer.php @@ -30,6 +30,7 @@ use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Core\Utility\PathUtility; use TYPO3\CMS\Core\SingletonInterface; +use TYPO3\CMS\Core\Page\PageRenderer as PageRendererCore; /** * Class/Function which adds the necessary ExtJS and pure JS stuff for themes. @@ -38,22 +39,23 @@ */ class PageRenderer implements SingletonInterface { + /** - * wrapper function called by hook (\TYPO3\CMS\Core\Page\PageRenderer->render-preProcess). + * Wrapper function called by hook (\TYPO3\CMS\Core\Page\PageRenderer->render-preProcess). * * @param array $parameters An array of available parameters * @param \TYPO3\CMS\Core\Page\PageRenderer $pageRenderer The parent object that triggered this hook - * * @return void */ - public function addJSCSS(array $parameters, \TYPO3\CMS\Core\Page\PageRenderer $pageRenderer) - { - // Add javascript + public function addJSCSS(array $parameters, PageRendererCore $pageRenderer) + { + // Add JavaScript $pageRenderer->loadRequireJsModule('TYPO3/CMS/Themes/ThemesBackendTca'); - // Add css + // Add CSS $extensionFile = 'Resources/Public/Stylesheet/ThemesBackendTca.css'; $absolutePath = ExtensionManagementUtility::extPath('themes', $extensionFile); $filename = PathUtility::getAbsoluteWebPath($absolutePath); $pageRenderer->addCssFile($filename, 'stylesheet', 'screen'); } + } diff --git a/Classes/Provider/PageTsBackendLayoutDataProvider.php b/Classes/Provider/PageTsBackendLayoutDataProvider.php deleted file mode 100755 index 4a0e80d7..00000000 --- a/Classes/Provider/PageTsBackendLayoutDataProvider.php +++ /dev/null @@ -1,293 +0,0 @@ - - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -use TYPO3\CMS\Backend\Utility\BackendUtility; -use TYPO3\CMS\Backend\View\BackendLayout\BackendLayout; -use TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection; -use TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext; -use TYPO3\CMS\Backend\View\BackendLayout\DataProviderInterface; -use TYPO3\CMS\Core\Utility\GeneralUtility; - -/** - * This Provider adds Backend Layouts based on PageTsConfig. - * - * = Example = - * mod { - * web_layout { - * BackendLayouts { - * example { - * title = Example - * config { - * backend_layout { - * colCount = 1 - * rowCount = 2 - * rows { - * 1 { - * columns { - * 1 { - * name = LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:colPos.I.3 - * colPos = 3 - * colspan = 1 - * } - * } - * } - * 2 { - * columns { - * 1 { - * name = Main - * colPos = 0 - * colspan = 1 - * } - * } - * } - * } - * } - * } - * icon = EXT:example_extension/Resources/Public/Images/BackendLayouts/default.gif - * } - * } - * } - * } - */ -class PageTsBackendLayoutDataProvider implements DataProviderInterface -{ - /** - * Internal Backend Layout stack. - * - * @var array - */ - protected $backendLayouts = []; - - /** - * PageTs Config. - * - * @var array - */ - protected $pageTsConfig = []; - - /** - * PageId. - * - * @var int - */ - protected $pageId = 0; - - /** - * Set PageTsConfig. - * - * @param array $pageTsConfig - * - * @return void - */ - protected function setPageTsConfig(array $pageTsConfig) - { - $this->pageTsConfig = $pageTsConfig; - } - - /** - * Get PageTsConfig. - * - * @return array - */ - protected function getPageTsConfig() - { - return $this->pageTsConfig; - } - - /** - * Set PageId. - * - * @param int $pageId - * - * @return void - */ - protected function setPageId($pageId) - { - $this->pageId = (int) $pageId; - } - - /** - * Get PageId. - * - * @return int - */ - protected function getPageId() - { - return (int) $this->pageId; - } - - /** - * Gets PageTsConfig from DataProviderContext if available, - * if not it will be generated for the current Page. - * - * @param DataProviderContext $dataProviderContext - * - * @return void - */ - protected function generatePageTsConfig($dataProviderContext = null) - { - if ($dataProviderContext === null) { - $pageId = $this->getPageId(); - $pageId = $pageId > 0 ? $pageId : (int) GeneralUtility::_GP('id'); - $pageTsConfig = BackendUtility::getPagesTSconfig($pageId); - } else { - $pageTsConfig = $dataProviderContext->getPageTsConfig(); - } - $this->setPageTsConfig($pageTsConfig); - } - - /** - * Generate the Backend Layout configs. - * - * @param DataProviderContext $dataProviderContext - * - * @return void - */ - protected function generateBackendLayouts($dataProviderContext = null) - { - $this->generatePageTsConfig($dataProviderContext); - $pageTsConfig = $this->getPageTsConfig(); - if (!empty($pageTsConfig['mod.']['web_layout.']['BackendLayouts.'])) { - $backendLayouts = (array) $pageTsConfig['mod.']['web_layout.']['BackendLayouts.']; - foreach ($backendLayouts as $identifier => $data) { - $backendLayout = $this->generateBackendLayoutFromTsConfig($identifier, $data); - $this->attachBackendLayout($backendLayout); - } - } - } - - /** - * Generates a Backend Layout from PageTsConfig array. - * - * @return mixed - */ - protected function generateBackendLayoutFromTsConfig($identifier, $data) - { - if (!empty($data['config.']['backend_layout.']) && is_array($data['config.']['backend_layout.'])) { - $backendLayout['uid'] = substr($identifier, 0, -1); - $backendLayout['title'] = ($data['title']) ? $data['title'] : $backendLayout['uid']; - $backendLayout['icon'] = ($data['icon']) ? $data['icon'] : ''; - // Convert PHP array back to plain TypoScript so it can be procecced - $config = \TYPO3\CMS\Core\Utility\ArrayUtility::flatten($data['config.']); - $backendLayout['config'] = ''; - foreach ($config as $row => $value) { - $backendLayout['config'] .= $row.' = '.$value."\r\n"; - } - - return $backendLayout; - } - } - - /** - * Attach Backend Layout to internal Stack. - * - * @param mixed $backendLayout - */ - protected function attachBackendLayout($backendLayout = null) - { - if ($backendLayout) { - $this->backendLayouts[$backendLayout['uid']] = $backendLayout; - } - } - - /** - * @param DataProviderContext $dataProviderContext - * @param BackendLayoutCollection $backendLayoutCollection - * - * @return void - */ - public function addBackendLayouts(DataProviderContext $dataProviderContext, BackendLayoutCollection $backendLayoutCollection) - { - $this->generateBackendLayouts($dataProviderContext); - foreach ($this->backendLayouts as $backendLayoutConfig) { - $backendLayout = $this->createBackendLayout($backendLayoutConfig); - $backendLayoutCollection->add($backendLayout); - } - } - - /** - * Gets a backend layout by (regular) identifier. - * - * @param string $identifier - * @param int $pageId - * - * @return null|BackendLayout - */ - public function getBackendLayout($identifier, $pageId) - { - $this->setPageId($pageId); - $this->generateBackendLayouts(); - $backendLayout = null; - if (array_key_exists($identifier, $this->backendLayouts)) { - return $this->createBackendLayout($this->backendLayouts[$identifier]); - } - - return $backendLayout; - } - - /** - * Creates a new backend layout using the given record data. - * - * @param array $data - * - * @return BackendLayout - */ - protected function createBackendLayout(array $data) - { - $backendLayout = BackendLayout::create($data['uid'], $data['title'], $data['config']); - $backendLayout->setIconPath($this->getIconPath($data['icon'])); - $backendLayout->setData($data); - - return $backendLayout; - } - - /** - * Gets and sanitizes the icon path. - * - * @param string $icon Name of the icon file - * - * @return string - */ - protected function getIconPath($icon) - { - $iconPath = ''; - if (!empty($icon)) { - $iconPath = $icon; - } - - return $iconPath; - } -} diff --git a/Configuration/TypoScript/setup.typoscript b/Configuration/TypoScript/setup.typoscript index 5fb19119..5eb27a21 100755 --- a/Configuration/TypoScript/setup.typoscript +++ b/Configuration/TypoScript/setup.typoscript @@ -13,7 +13,7 @@ config { # Plugin configuration plugin.tx_themes { - settings { + view { templateName = TEXT templateName { cObject = TEXT diff --git a/Resources/Private/Layouts/Backend.html b/Resources/Private/Layouts/Backend.html index 3eb4e0ba..565d4b57 100755 --- a/Resources/Private/Layouts/Backend.html +++ b/Resources/Private/Layouts/Backend.html @@ -1,4 +1,4 @@
-
\ No newline at end of file + diff --git a/Resources/Private/Partials/Themes/ThemeSmallPreview.html b/Resources/Private/Partials/Themes/ThemeSmallPreview.html index fa355881..c6bb32a0 100755 --- a/Resources/Private/Partials/Themes/ThemeSmallPreview.html +++ b/Resources/Private/Partials/Themes/ThemeSmallPreview.html @@ -3,8 +3,8 @@ xmlns:themes="http://typo3.org/ns/KayStrobach/Themes/ViewHelpers">
- - {screenshot.caption} + +
@@ -49,4 +49,4 @@

- \ No newline at end of file + diff --git a/ext_localconf.php b/ext_localconf.php index 0638554f..dc73a69c 100755 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -7,12 +7,13 @@ /* * Add page typoscript for new content element wizard */ -\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig(''); +$tsconfig = ''; +\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig($tsconfig); /* * Register hook to inject themes */ -$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Tx_Themes_Domain_Repository_ThemeRepository']['init'][] +$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['KayStrobach\\Themes\\Domain\\Repository\\ThemeRepository']['init'][] = 'KayStrobach\\Themes\\Hooks\\ThemesDomainRepositoryThemeRepositoryInitHook->init'; /* @@ -36,20 +37,12 @@ ); unset($signalSlotDispatcher); -/* - * register hook to inject BeLayoutTsprovider - */ -if (TYPO3_MODE === 'BE') { - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['BackendLayoutDataProvider']['pagets'] - = 'KayStrobach\\Themes\\Provider\\PageTsBackendLayoutDataProvider'; -} - /* * register frontend plugin to allow usage of extbase controller */ \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin( 'KayStrobach.' . $_EXTKEY, 'Theme', - ['Theme' => 'index',], + ['Theme' => 'index'], [] );