Skip to content

Commit

Permalink
[TASK] Add compatibility with TYPO3 v10 LTS
Browse files Browse the repository at this point in the history
Since TYPO3 v10.3 the ModuleTemplate is used for LinkBrowser
and BackendController.

However, BackendController + LinkBrowser have their own hooks,
so DocumentTemplate does not need to be used anymore.

Fixes: #8
  • Loading branch information
bmack committed Apr 24, 2020
1 parent 5aaded7 commit 0d63cd0
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 6 deletions.
57 changes: 57 additions & 0 deletions 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,62 @@
*/
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);
list($version) = explode('.', VersionNumberUtility::getCurrentTypo3Version());
$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
7 changes: 4 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 All @@ -54,6 +54,7 @@ define([
handles: 'e, w',
minWidth: 200,
create: function () {
console.debug(container);
container.find('.ui-resizable-e').dblclick(function (e) {
var width = contentWidth();
if (width !== false) {
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;
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"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",
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'version' => '1.2.1',
'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 0d63cd0

Please sign in to comment.