Skip to content

Commit

Permalink
Rebuild backend modules #360
Browse files Browse the repository at this point in the history
  • Loading branch information
digedag committed Feb 26, 2025
1 parent 752ca0f commit f4e8abe
Show file tree
Hide file tree
Showing 22 changed files with 263 additions and 62 deletions.
28 changes: 19 additions & 9 deletions Classes/Backend/Form/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace Sys25\RnBase\Backend\Form;

use Sys25\RnBase\Backend\Module\IModule;
use Sys25\RnBase\Utility\TYPO3;
use tx_rnbase;
use TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord;

/***************************************************************
* Copyright notice
*
* (c) 2016-2021 Rene Nitzsche ([email protected])
* (c) 2016-2025 Rene Nitzsche ([email protected])
* All rights reserved
*
* This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -49,6 +51,11 @@ class FormBuilder
*/
private $formResultCompiler;

/**
* @var IModule
*/
private $module;

/**
* @var array
*/
Expand All @@ -57,16 +64,17 @@ class FormBuilder
public function __construct()
{
/**
* @var \TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord
* @var TcaDatabaseRecord
*/
$formDataGroup = tx_rnbase::makeInstance('TYPO3\\CMS\\Backend\\Form\\FormDataGroup\\TcaDatabaseRecord');
$this->formDataCompiler = tx_rnbase::makeInstance('TYPO3\\CMS\\Backend\\Form\\FormDataCompiler', $formDataGroup);
$this->nodeFactory = tx_rnbase::makeInstance('TYPO3\\CMS\\Backend\\Form\\NodeFactory');
$this->formResultCompiler = tx_rnbase::makeInstance('TYPO3\\CMS\\Backend\\Form\\FormResultCompiler');
}

public function initDefaultBEmode()
public function setModule(IModule $module)
{
$this->module = $module;
}

/**
Expand Down Expand Up @@ -128,7 +136,13 @@ protected function compileFormData($table, $uid, $record)
'returnUrl' => '',
];
}
$this->formDataCache[$cacheKey] = $this->formDataCompiler->compile($formDataCompilerInput);
$formDataCompilerInput['request'] = $this->module->getRequest();

if (TYPO3::isTYPO130OrHigher()) {
$this->formDataCache[$cacheKey] = $this->formDataCompiler->compile($formDataCompilerInput, tx_rnbase::makeInstance(TcaDatabaseRecord::class));
} else {
$this->formDataCache[$cacheKey] = $this->formDataCompiler->compile($formDataCompilerInput);
}
if ($this->isNEWRecord($uid)) {
// Override generated with given uid
$this->formDataCache[$cacheKey]['databaseRow']['uid'] = $uid;
Expand Down Expand Up @@ -171,11 +185,7 @@ public function getSoloField($table, $row, $fieldName)
*/
public function printNeededJSFunctions_top()
{
if (TYPO3::isTYPO90OrHigher()) {
$result = $this->formResultCompiler->addCssFiles();
} else {
$result = $this->formResultCompiler->JStop();
}
$result = $this->formResultCompiler->addCssFiles();

return $result;
}
Expand Down
7 changes: 4 additions & 3 deletions Classes/Backend/Form/ToolBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Sys25\RnBase\Backend\Utility\Icons;
use Sys25\RnBase\Backend\Utility\TCA;
use Sys25\RnBase\Frontend\Request\Parameters;
use Sys25\RnBase\Utility\LanguageTool;
use Sys25\RnBase\Utility\Link;
use Sys25\RnBase\Utility\Math;
use Sys25\RnBase\Utility\Misc;
Expand Down Expand Up @@ -107,7 +108,7 @@ public function init(DocumentTemplate $doc, IModule $module)

// TCEform für das Formular erstellen
$this->form = tx_rnbase::makeInstance(FormBuilder::class);
$this->form->initDefaultBEmode();
$this->form->setModule($module);
}

/**
Expand Down Expand Up @@ -1150,7 +1151,7 @@ public function showTabMenu($pid, $name, $modName, $entries)
];
$SETTINGS = BackendUtility::getModuleData(
$MENU,
T3General::_GP('SET'),
Parameters::_GP('SET'),
$modName
);
$menuItems = [];
Expand Down Expand Up @@ -1351,7 +1352,7 @@ protected function buildDataHandlerUri(string $params, $redirect)
}

/**
* @return LanguageService|\TYPO3\CMS\Lang\LanguageService
* @return LanguageTool
*/
public function getLanguageService()
{
Expand Down
4 changes: 3 additions & 1 deletion Classes/Backend/Module/BaseModFunc.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class BaseModFunc implements IModFunc
/* @var $mod IModule */
protected $mod;

public function init(IModule $module, $conf)
private function init(IModule $module, $conf)
{
$this->mod = $module;
}
Expand All @@ -64,7 +64,9 @@ public function getModule()
public function main(?ServerRequestInterface $request = null)
{
if (TYPO3::isTYPO121OrHigher()) {
/** @var IModule $modFuncFrame */
$modFuncFrame = tx_rnbase::makeInstance(ModFuncFrame::class);
$this->init($modFuncFrame, []);

return $modFuncFrame->render($this, function () { return $this->renderOutput(); }, $request);
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Backend/Module/BaseModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected function prepareModuleParts($parts)

$parts->setContent($this->moduleContent());
$parts->setButtons($this->getButtons());
$parts->setTitle($GLOBALS['LANG']->getLL('title'));
$parts->setTitle($this->getFormTool()->getLL('title'));
$parts->setFuncMenu($this->getFuncMenu());
// if we got no array the user got no permissions for the
// selected page or no page is selected
Expand Down Expand Up @@ -625,6 +625,6 @@ public function getRouteIdentifier()

public function getLanguageService()
{
return $GLOBALS['LANG'];
return $this->getFormTool()->getLanguageService()
}
}
2 changes: 2 additions & 0 deletions Classes/Backend/Module/BaseScriptClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
* $GLOBALS['SOBE']->main();
*
* TODO: check TYPO3 versions used.
*
* @deprecated
*/
abstract class BaseScriptClass
{
Expand Down
2 changes: 1 addition & 1 deletion Classes/Backend/Module/IModFunc.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface IModFunc

public const ICON_FATAL = 3;

public function init(IModule $module, $conf);
// public function init(IModule $module, $conf);

/**
* Module identifier for ts_config.
Expand Down
8 changes: 7 additions & 1 deletion Classes/Backend/Module/IModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Sys25\RnBase\Backend\Module;

use Psr\Http\Message\ServerRequestInterface;
use Sys25\RnBase\Backend\Form\ToolBox;
use Sys25\RnBase\Backend\Template\Override\DocumentTemplate;
use Sys25\RnBase\Configuration\ConfigurationInterface;
use Sys25\RnBase\Utility\LanguageTool;

/***************************************************************
* Copyright notice
Expand Down Expand Up @@ -36,6 +38,8 @@ interface IModule
*/
public function getDoc();

public function getRequest(): ?ServerRequestInterface;

/**
* Returns the form tool.
*
Expand Down Expand Up @@ -76,6 +80,8 @@ public function getRouteIdentifier();
*/
public function getPid();

public function render(IModFunc $modFunc, callable $renderFunc, ServerRequestInterface $request);

/**
* Submenu String for the marker ###TABS###.
*
Expand Down Expand Up @@ -105,7 +111,7 @@ public function setSelector($selectorString);
public function addMessage($message, $title = '', $severity = 0, $storeInSession = false);

/**
* @return \TYPO3\CMS\Core\Localization\LanguageService
* @return LanguageTool
*/
public function getLanguageService();
}
18 changes: 13 additions & 5 deletions Classes/Backend/Module/ModFuncFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class ModFuncFrame implements IModule
protected $doc;
protected $tabs;

private ?ServerRequestInterface $request = null;

/**
* @var array
*/
Expand All @@ -74,8 +76,14 @@ public function __construct(
$this->pageRenderer = $pageRenderer;
}

public function getRequest(): ?ServerRequestInterface
{
return $this->request;
}

public function render(IModFunc $modFunc, callable $renderFunc, ServerRequestInterface $request)
{
$this->request = $request;
$this->modFunc = $modFunc;
$this->moduleIdentifier = $modFunc->getModuleIdentifier();
$this->id = (int) ($request->getQueryParams()['id'] ?? $request->getParsedBody()['id'] ?? 0);
Expand All @@ -88,11 +96,11 @@ public function render(IModFunc $modFunc, callable $renderFunc, ServerRequestInt
}
$this->getLanguageService()->registerLangFile('EXT:rn_base/Resources/Private/Language/locallang.xlf');

$this->modFunc->init($this, [
// 'form' => $this->getFormTag(),
// 'docstyles' => $this->getDocStyles(),
// 'template' => $this->getModuleTemplateFilename(),
]);
// $this->modFunc->init($this, [
// // 'form' => $this->getFormTag(),
// // 'docstyles' => $this->getDocStyles(),
// // 'template' => $this->getModuleTemplateFilename(),
// ]);
// Rahmen rendern
$this->moduleTemplate = $this->createModuleTemplate($request);
// Die Variable muss gesetzt sein.
Expand Down
17 changes: 10 additions & 7 deletions Classes/Backend/Template/ModuleTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ protected function renderContent12(ModuleParts $parts)
{
/** @var ModuleTemplateFactory $factory */
$factory = tx_rnbase::makeInstance(ModuleTemplateFactory::class);
$view = $factory->create($this->options['request']);
$moduleTemplate = $factory->create($this->options['request']);
$content = '';
// $moduleTemplate->getPageRenderer()->loadJquery();
$view->getDocHeaderComponent()->setMetaInformation($parts->getPageInfo());
$this->registerMenu($view, $parts);
$moduleTemplate->getDocHeaderComponent()->setMetaInformation($parts->getPageInfo());
$this->registerMenu($moduleTemplate, $parts);

$content .= $this->options['form'] ?? $this->module->buildFormTag();

$view->makeDocHeaderModuleMenu(['id' => $this->module->getPid()]);
$moduleTemplate->makeDocHeaderModuleMenu(['id' => $this->module->getPid()]);

if (is_string($parts->getFuncMenu())) {
// Fallback für Module, die das FuncMenu selbst als String generieren
Expand All @@ -106,7 +106,7 @@ protected function renderContent12(ModuleParts $parts)
$content .= '</form>';

// Es ist sinnvoll, die Buttons nach der Generierung des Content zu generieren
$this->generateButtons($view, $parts);
$this->generateButtons($moduleTemplate, $parts);

// Workaround: jumpUrl wieder einfügen
// @TODO Weg finden dass ohne das DocumentTemplate zu machen
Expand All @@ -115,9 +115,12 @@ protected function renderContent12(ModuleParts $parts)
// @TODO haupttemplate eines BE moduls enthält evtl. JS/CSS etc.
// das wurde bisher über das DocumentTemplate eingefügt, was jetzt
// nicht mehr geht. Dafür muss ein Weg gefunden werden.
$view->setContent($content);
// $moduleTemplate->setContent($content);
$moduleTemplate->assign('content', $content);

return $view->renderContent();
return $moduleTemplate->render('ModuleTemplate/Module.html');

return $moduleTemplate->renderContent();
}

/**
Expand Down
23 changes: 18 additions & 5 deletions Classes/Backend/Template/Override/DocumentTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

use Sys25\RnBase\Backend\Utility\Icons;
use Sys25\RnBase\Utility\Files;
use Sys25\RnBase\Utility\LanguageTool;
use Sys25\RnBase\Utility\Strings;
use Sys25\RnBase\Utility\T3General;
use Sys25\RnBase\Utility\TYPO3;
use tx_rnbase;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Localization\Locale;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand Down Expand Up @@ -97,17 +100,22 @@ function jumpToUrl(URL) {

/** @var LanguageService */
private $lang;
/** @var LanguageTool */
private $languageTool;

/**
* Constructor.
*/
public function __construct()
{
public function __construct(
?LanguageTool $languageTool = null,
?\TYPO3\CMS\Core\Messaging\FlashMessageService $flashMessageService = null
) {
$this->languageTool = $languageTool ?? tx_rnbase::makeInstance(LanguageTool::class);
$this->lang = $this->languageTool->getLanguageService();
// Initializes the page rendering object:
$this->initPageRenderer();

$this->flashMessageService = T3General::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
$this->lang = $GLOBALS['LANG'];
$this->flashMessageService = $flashMessageService ?? tx_rnbase::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
}

/**
Expand Down Expand Up @@ -429,8 +437,13 @@ protected function initPageRenderer()
if (null !== $this->pageRenderer) {
return;
}
$lang = $this->getLangSrv()->lang;
if (TYPO3::isTYPO121OrHigher()) {
$lang = new Locale($lang);
}

$this->pageRenderer = T3General::makeInstance(PageRenderer::class);
$this->pageRenderer->setLanguage($GLOBALS['LANG']->lang);
$this->pageRenderer->setLanguage($lang);
$this->pageRenderer->enableConcatenateCss();
$this->pageRenderer->enableConcatenateJavascript();
$this->pageRenderer->enableCompressCss();
Expand Down
Loading

0 comments on commit f4e8abe

Please sign in to comment.