Skip to content

Commit

Permalink
[TASK] Migration for TYPO3 9.5 - see ChangeLog.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdeuling committed Jul 4, 2019
1 parent 891fbb5 commit ead9417
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 494 deletions.
4 changes: 2 additions & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>

Expand Down
56 changes: 27 additions & 29 deletions Classes/Controller/EditorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -192,45 +193,45 @@ 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'])
->setHref($uriBuilder->reset()->uriFor($action['action'], [], 'Editor'))
->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;
}

Expand Down Expand Up @@ -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));
}

/**
Expand Down
31 changes: 9 additions & 22 deletions Classes/Controller/ThemeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,14 @@ 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.
*
* @return void
*/
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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}

/**
Expand Down
89 changes: 42 additions & 47 deletions Classes/Domain/Model/AbstractTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 2 additions & 10 deletions Classes/Domain/Model/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
}
Expand Down
Loading

0 comments on commit ead9417

Please sign in to comment.