Skip to content

Commit

Permalink
[TASK] TYPO3 11 LTS Compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Lehmann committed Oct 6, 2021
1 parent be12bb5 commit 8ff9326
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Classes/Controller/FilterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function fetchFilterAction(ServerRequestInterface $request): ResponseInte
/** @var NewContentElementController $controller */
$controller = GeneralUtility::makeInstance(NewContentElementController::class);
/** @var HtmlResponse $htmlResponse */
$htmlResponse = $controller->wizardAction($request);
$htmlResponse = $controller->handleRequest($request);

return $htmlResponse;
}
Expand Down
16 changes: 5 additions & 11 deletions Classes/Controller/NewContentElementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,23 @@
namespace Lemming\PageTreeFilter\Controller;

use Lemming\PageTreeFilter\Utility\ConfigurationUtility;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;

class NewContentElementController extends \TYPO3\CMS\Backend\Controller\ContentElement\NewContentElementController
{
protected function init(ServerRequestInterface $request)
public function handleRequest(ServerRequestInterface $request): ResponseInterface
{
$queryParameters = $request->getQueryParams();
$queryParameters['id'] = ConfigurationUtility::getPageId();
$requestWithPageId = $request->withQueryParams($queryParameters);
parent::init($requestWithPageId);

$this->menuItemView->assignMultiple([
'isVersion10' => version_compare(VersionNumberUtility::getNumericTypo3Version(), '11', '<')
]);
return parent::handleRequest($requestWithPageId);
}

public function getWizards(): array
Expand All @@ -49,7 +46,6 @@ protected function appendPageTypes(array $wizards): array
$wizards['pagetypes_' . $no] = [
'title' => $this->getLanguageService()->sL($pageTypeConfiguration[0]),
'iconIdentifier' => $GLOBALS['TCA']['pages']['ctrl']['typeicon_classes'][$pageTypeConfiguration[1]],
'params' => '', // if missing it leads to an exception
'filter' => sprintf('table=pages doktype=%d', $pageTypeConfiguration[1]),
'disabled' => !in_array($pageTypeConfiguration[1], $usedPageTypes)
];
Expand Down Expand Up @@ -82,7 +78,6 @@ protected function appendRecords(array $wizards): array
$wizards['records_' . $tableName] = [
'title' => $this->getLanguageService()->sL($tableConfiguration['ctrl']['title']),
'iconIdentifier' => $iconIdentifier,
'params' => '', // if missing it leads to an exception
'filter' => sprintf('table=%s', $tableName),
'disabled' => $this->areRecordsInTable($tableName) ? false : true
];
Expand Down Expand Up @@ -161,12 +156,11 @@ protected function areRecordsInTable($tableName): bool
return $oneRecord !== false;
}

protected function getFluidTemplateObject(string $filename = 'Main.html'): StandaloneView
protected function getFluidTemplateObject(string $templateName): StandaloneView
{
/** @var StandaloneView $view */
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:pagetreefilter/Resources/Private/Templates/Filter/' . $filename));
$view->getRequest()->setControllerExtensionName('Pagetreefilter');
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:pagetreefilter/Resources/Private/Templates/Filter/' . $templateName . '.html'));

return $view;
}
Expand Down
19 changes: 0 additions & 19 deletions Resources/Private/Templates/Filter/Main.html

This file was deleted.

43 changes: 21 additions & 22 deletions Resources/Private/Templates/Filter/MenuItem.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
<html
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:pagetreefilter="http://typo3.org/ns/Lemming/PageTreeFilter/ViewHelpers"
data-namespace-typo3-fluid="true">
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true"
xmlns:pagetreefilter="http://typo3.org/ns/Lemming/PageTreeFilter/ViewHelpers">

<div class="{f:if(condition: '{isVersion10}', then: 'media')} t3js-media-new-content-element-wizard media-new-content-element-wizard">
<a href="#" class="pagetreefilter{f:if(condition: '{isVersion10}', else: ' media')}{f:if(condition: '{wizardInformation.disabled}', then: ' disabled')}"
data-pagetreefilter="{f:if(condition: '{wizardInformation.filter}', then: '{wizardInformation.filter}', else: '{pagetreefilter:buildFilter(wizardInformation: \'{wizardInformation}\')}')}"
data-bs-slide="next">

<f:if condition="{content}">
{content -> f:format.raw()}
</f:if>
<div class="media-left">
{icon -> f:format.raw()}
</div>
<div class="media-body">

<strong>{wizardInformation.title -> f:format.htmlspecialchars()}</strong>
<br/>
{wizardInformation.description -> f:format.nl2br() -> f:format.htmlspecialchars()}
</div>
<div class="t3js-media-new-content-element-wizard media-new-content-element-wizard">
<a class="pagetreefilter btn btn-link media p-0 text-start {f:if(condition: '{wizardInformation.disabled}', then: ' disabled')}"
data-pagetreefilter="{f:if(condition: '{wizardInformation.filter}', then: '{wizardInformation.filter}', else: '{pagetreefilter:buildFilter(wizardInformation: \'{wizardInformation}\')}')}">
<f:render section="itemContent" arguments="{_all}" />
</a>
</div>

</html>
<f:section name="itemContent">
<f:if condition="{content}">
{content -> f:format.raw()}
</f:if>
<div class="media-left">
{icon -> f:format.raw()}
</div>
<div class="media-body">
<strong>{wizardInformation.title -> f:format.htmlspecialchars()}</strong>
<br/>
{wizardInformation.description -> f:format.nl2br() -> f:format.htmlspecialchars()}
</div>
</f:section>

</html>
17 changes: 17 additions & 0 deletions Resources/Private/Templates/Filter/Wizard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">

<f:if condition="{hasAccess}">
<f:then>
<div class="t3-new-content-element-wizard-window">
<div class="container mt-2">
<f:translate key="wizard_description"/>
</div>
<div class="t3-new-content-element-wizard-inner">
{renderedTabs -> f:format.raw()}
</div>
</div>
</f:then>
<f:else>
<p><f:translate key="wizard_error_message"/></p>
</f:else>
</f:if>
5 changes: 5 additions & 0 deletions Resources/Public/Css/Backend/pagetreefilter.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
.pagetreefilter-highlighted.node-over,
.pagetreefilter-highlighted.node-selected {
fill-opacity: 0.3;
}

.pagetreefilter-wizard .modal-body {
background-color: #fafafa;
padding: 0;
}
29 changes: 11 additions & 18 deletions Resources/Public/JavaScript/PageTreeFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,28 @@ require([], function () {
);
}

document.querySelector('#pagetreefilter').onclick = function() { showSubMenu(); openWizard(); }
}

// TYPO3 10
function showSubMenu()
{
defaultFilterButton = document.querySelector('.svg-toolbar__menu div[data-tree-show-submenu="filter"]');
if (defaultFilterButton !== null) {
defaultFilterButton.click();
}
document.querySelector('#pagetreefilter').onclick = function() { openWizard(); }
}

function openWizard()
{
TYPO3.Modal.loadUrl(
TYPO3.lang.pagetreefilter_wizard_title,
TYPO3.Severity.info,
[],
TYPO3.settings.ajaxUrls.pagetreefilter_fetch_filter,
function () {
TYPO3.Modal.advanced({
size: 'medium',
type: 'ajax',
title: TYPO3.lang.pagetreefilter_wizard_title,
severity: TYPO3.Severity.info,
ajaxCallback: function () {
let links = document.querySelectorAll('a.pagetreefilter');
links.forEach((button) => {
button.addEventListener('click', () => {
applyFilter(button.getAttribute('data-pagetreefilter'));
TYPO3.Modal.dismiss()
});
});
}
)
},
content: TYPO3.settings.ajaxUrls.pagetreefilter_fetch_filter,
additionalCssClasses: ['pagetreefilter-wizard']
});
}

function applyFilter(filter)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require": {
"typo3/cms-backend": "^10.4 || ^11"
"typo3/cms-backend": "^11.5"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 3 additions & 3 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
'title' => 'Pagetree Filter',
'description' => 'Filter the pagetree for records and content elements. For simplicity it comes with a wizard.',
'category' => 'be',
'state' => 'beta',
'state' => 'stable',
'clearCacheOnLoad' => 1,
'author' => 'Christoph Lehmann',
'author_email' => '[email protected]',
'author_company' => '',
'version' => '0.1.0',
'version' => '1.0.0',
'constraints' => [
'depends' => [
'typo3' => '10.4.0-11.4.99'
'typo3' => '11.5.0-11.5.99'
],
'conflicts' => [],
'suggests' => [],
Expand Down

0 comments on commit 8ff9326

Please sign in to comment.