Skip to content

Commit

Permalink
[TASK] Add compatibility with TYPO3 v10 LTS
Browse files Browse the repository at this point in the history
  • Loading branch information
wazum committed Apr 28, 2020
2 parents 5aaded7 + 0d63cd0 commit 55c17c5
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 9 deletions.
57 changes: 56 additions & 1 deletion Classes/Hooks/Backend/Template/DocumentTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Wazum\PagetreeResizable\Hooks\Backend\Template;

use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;

/**
Expand All @@ -14,6 +15,60 @@
*/
class DocumentTemplate
{
/**
* Executed when makeInstance is used (= in the link handler)
* Used in TYPO3 v10, but can replace all other parts as well.
*/
public function __construct()
{
if (TYPO3_MODE === 'BE') {
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
if ($width = $this->getUserElementBrowserTreeWidth()) {
$pageRenderer->addCssInlineBlock('wazum/pagetree-resizable', '
.element-browser-main .element-browser-main-sidebar {
width: ' . $width . 'px;
}
');
}
$this->includeRequiredResources();
}
}

/**
* Used within the main backend module to add JS + CSS.
*/
public function mainBackendModule()
{
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
if ($width = $this->getUserPageTreeWidth()) {
$pageRenderer->addCssInlineBlock('wazum/pagetree-resizable', '
.scaffold-content-navigation-expanded .scaffold-content-navigation {
width: ' . $width . 'px;
}
.scaffold-content-navigation-expanded .scaffold-content-module {
left: ' . $width . 'px;
}
');
}
$this->includeRequiredResources();
}

/**
* Load CSS & JS resources into PageRenderer
*/
protected function includeRequiredResources()
{
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
[$version] = explode('.', VersionNumberUtility::getCurrentTypo3Version());

This comment has been minimized.

Copy link
@kitzberger

kitzberger May 6, 2020

@wazum, I'm afraid, this breaks compatibility with php 7.0 ;-/
Non-numerical keys are only allowed for php 7.1+

$pageRenderer->addCssFile('EXT:pagetree_resizable/Resources/Public/Stylesheet/PagetreeResizable.css');
if ((int)$version === 8) {
$pageRenderer->loadRequireJsModule('TYPO3/CMS/PagetreeResizable/PagetreeResizable8');
} else {
// TYPO3 9, 10
$pageRenderer->loadRequireJsModule('TYPO3/CMS/PagetreeResizable/PagetreeResizable9');
}
}

/**
* @param array $parameters
* @param \TYPO3\CMS\Backend\Template\DocumentTemplate $parent
Expand Down Expand Up @@ -45,7 +100,7 @@ public function preHeaderRenderHook(array $parameters, \TYPO3\CMS\Backend\Templa
}
}

list($version) = explode('.', VersionNumberUtility::getCurrentTypo3Version());
[$version] = explode('.', VersionNumberUtility::getCurrentTypo3Version());
$pageRenderer->addCssFile('EXT:pagetree_resizable/Resources/Public/Stylesheet/PagetreeResizable.css');
if ((int)$version === 8) {
$pageRenderer->loadRequireJsModule('TYPO3/CMS/PagetreeResizable/PagetreeResizable8');
Expand Down
6 changes: 3 additions & 3 deletions Resources/Public/JavaScript/PagetreeResizable.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ define([
isPageModule = true;
}
// Link browser
else if ($('.element-browser .element-browser-main .element-browser-main-sidebar').length) {
container = $('.element-browser .element-browser-main .element-browser-main-sidebar');
else if ($('.element-browser-main .element-browser-main-sidebar').length) {
container = $('.element-browser-main .element-browser-main-sidebar');
styles = function (width) {
return '<style>.element-browser .element-browser-main .element-browser-main-sidebar{width:' + width + 'px}</style>';
return '<style>.element-browser-main .element-browser-main-sidebar{width:' + width + 'px}</style>';
};
contentWidth = function () {
if ($('.element-browser-main-sidebar .element-browser-body ul.list-tree-root').length) {
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/Stylesheet/PagetreeResizable.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
.element-browser .element-browser-main .element-browser-main-sidebar {
width: auto !important;
}
}
}
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
"description": "Make the backend page tree horizontally resizable",
"require": {
"php": ">=7.0.0",
"typo3/cms-core": "^8.7 || ^9.5 || ^10.2"
"typo3/cms-core": "^8.7 || ^9.5 || ^10.4"
},
"type": "typo3-cms-extension",
"version": "1.2.1",
"autoload": {
"psr-4": {
"Wazum\\PagetreeResizable\\": "Classes"
Expand Down
4 changes: 2 additions & 2 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
'state' => 'stable',
'clearCacheOnLoad' => true,
'author_company' => 'wazum.com',
'version' => '1.2.1',
'version' => '1.3.0',
'constraints' => [
'depends' => [
'typo3' => '8.7.0-10.2.99',
'typo3' => '8.7.0-10.4.99',
]
]
];
6 changes: 6 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
if (TYPO3_MODE === 'BE') {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preHeaderRenderHook']['wazum/pagetree-resizeable'] =
\Wazum\PagetreeResizable\Hooks\Backend\Template\DocumentTemplate::class . '->preHeaderRenderHook';

// Necessary for TYPO3 v10
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['LinkBrowser']['hooks']['wazum/pagetree-resizeable']['handler'] =
\Wazum\PagetreeResizable\Hooks\Backend\Template\DocumentTemplate::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/backend.php']['renderPreProcess']['wazum/pagetree-resizeable'] =
\Wazum\PagetreeResizable\Hooks\Backend\Template\DocumentTemplate::class . '->mainBackendModule';
}

0 comments on commit 55c17c5

Please sign in to comment.