Commit 2cddc7c4 authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Benni Mack
Browse files

[TASK] Remove unused code from NewContentElementController

In #95331 the legacy usage of the wizard as a full document
has been removed. This patch removes some further leftovers.

- Unused definition of docheader buttons is removed
- Protected property $moduleTemplate is removed due to single usage
- Protected property $menuItemView is removed due to single usage
- Guard clause is added to prepareContent()

Resolves: #95339
Related: #95331
Releases: master
Change-Id: If022edf286ed8c0398a7434c1c87751dd4726b0f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/71225

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent d51861e6
......@@ -20,7 +20,6 @@ namespace TYPO3\CMS\Backend\Controller\ContentElement;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Backend\Tree\View\ContentCreationPagePositionMap;
use TYPO3\CMS\Backend\Utility\BackendUtility;
......@@ -95,18 +94,6 @@ class NewContentElementController
*/
protected $view;
/**
* @var StandaloneView
*/
protected $menuItemView;
/**
* ModuleTemplate object
*
* @var ModuleTemplate
*/
protected $moduleTemplate;
protected IconFactory $iconFactory;
protected PageRenderer $pageRenderer;
protected UriBuilder $uriBuilder;
......@@ -131,9 +118,7 @@ class NewContentElementController
*/
protected function init(ServerRequestInterface $request)
{
$this->moduleTemplate = $this->moduleTemplateFactory->create($request);
$this->view = $this->getFluidTemplateObject();
$this->menuItemView = $this->getFluidTemplateObject('MenuItem.html');
$lang = $this->getLanguageService();
$lang->includeLLFile('EXT:core/Resources/Private/Language/locallang_misc.xlf');
$lang->includeLLFile('EXT:backend/Resources/Private/Language/locallang_db_new_content_el.xlf');
......@@ -165,7 +150,7 @@ class NewContentElementController
public function wizardAction(ServerRequestInterface $request): ResponseInterface
{
$this->init($request);
$this->prepareContent();
$this->prepareContent($request);
return new HtmlResponse($this->view->render());
}
......@@ -191,109 +176,105 @@ class NewContentElementController
*
* @throws \UnexpectedValueException
*/
protected function prepareContent(): void
protected function prepareContent(ServerRequestInterface $request): void
{
// Setting up the buttons for docheader
$this->getButtons();
$hasAccess = $this->id && $this->pageInfo !== [];
if ($hasAccess) {
// If a column is pre-set
if (isset($this->colPos)) {
$onClickEvent = $this->onClickInsertRecord();
} else {
$onClickEvent = '';
}
// ***************************
// Creating content
// ***************************
// Wizard
$wizardItems = $this->getWizards();
// Wrapper for wizards
// Hook for manipulating wizardItems, wrapper, onClickEvent etc.
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms']['db_new_content_el']['wizardItemsHook'] ?? [] as $className) {
$hookObject = GeneralUtility::makeInstance($className);
if (!$hookObject instanceof NewContentElementWizardHookInterface) {
throw new \UnexpectedValueException(
$className . ' must implement interface ' . NewContentElementWizardHookInterface::class,
1227834741
);
}
$hookObject->manipulateWizardItems($wizardItems, $this);
$this->view->assign('hasAccess', $hasAccess);
if (!$hasAccess) {
return;
}
// If a column is pre-set
if (isset($this->colPos)) {
$onClickEvent = $this->onClickInsertRecord();
} else {
$onClickEvent = '';
}
// ***************************
// Creating content
// ***************************
// Wizard
$wizardItems = $this->getWizards();
// Wrapper for wizards
// Hook for manipulating wizardItems, wrapper, onClickEvent etc.
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms']['db_new_content_el']['wizardItemsHook'] ?? [] as $className) {
$hookObject = GeneralUtility::makeInstance($className);
if (!$hookObject instanceof NewContentElementWizardHookInterface) {
throw new \UnexpectedValueException(
$className . ' must implement interface ' . NewContentElementWizardHookInterface::class,
1227834741
);
}
$hookObject->manipulateWizardItems($wizardItems, $this);
}
// Traverse items for the wizard.
// An item is either a header or an item rendered with a radio button and title/description and icon:
$cc = ($key = 0);
$menuItems = [];
// Traverse items for the wizard.
// An item is either a header or an item rendered with a radio button and title/description and icon:
$cc = ($key = 0);
$menuItems = [];
$this->view->assignMultiple([
'hasClickEvent' => $onClickEvent !== '',
'onClickEvent' => 'function goToalt_doc() { ' . $onClickEvent . '}',
]);
foreach ($wizardItems as $wizardKey => $wInfo) {
$wizardOnClick = '';
if (isset($wInfo['header'])) {
$menuItems[] = [
'label' => $wInfo['header'] ?: '-',
'content' => ''
];
$key = count($menuItems) - 1;
$this->view->assignMultiple([
'hasClickEvent' => $onClickEvent !== '',
'onClickEvent' => 'function goToalt_doc() { ' . $onClickEvent . '}',
]);
foreach ($wizardItems as $wizardKey => $wInfo) {
$wizardOnClick = '';
if (isset($wInfo['header'])) {
$menuItems[] = [
'label' => $wInfo['header'] ?: '-',
'content' => ''
];
$key = count($menuItems) - 1;
} else {
if (!$onClickEvent) {
// Radio button:
$wizardOnClick = 'document.editForm.defValues.value=unescape(' . GeneralUtility::quoteJSvalue(rawurlencode($wInfo['params'])) . '); window.location.hash=\'#sel2\';';
// Onclick action for icon/title:
$aOnClick = 'document.getElementsByName(\'tempB\')[' . $cc . '].checked=1;' . $wizardOnClick . 'return false;';
} else {
if (!$onClickEvent) {
// Radio button:
$wizardOnClick = 'document.editForm.defValues.value=unescape(' . GeneralUtility::quoteJSvalue(rawurlencode($wInfo['params'])) . '); window.location.hash=\'#sel2\';';
// Onclick action for icon/title:
$aOnClick = 'document.getElementsByName(\'tempB\')[' . $cc . '].checked=1;' . $wizardOnClick . 'return false;';
} else {
$aOnClick = "document.editForm.defValues.value=unescape('" . rawurlencode($wInfo['params']) . "');goToalt_doc();";
}
$aOnClick = "document.editForm.defValues.value=unescape('" . rawurlencode($wInfo['params']) . "');goToalt_doc();";
}
// Go to DataHandler directly instead of FormEngine - Only when colPos must not be selected
if (($wInfo['saveAndClose'] ?? false) && $onClickEvent !== '') {
$urlParams = [];
$id = StringUtility::getUniqueId('NEW');
parse_str($wInfo['params'], $urlParams);
$urlParams['data']['tt_content'][$id] = $urlParams['defVals']['tt_content'] ?? [];
$urlParams['data']['tt_content'][$id]['colPos'] = $this->colPos;
$urlParams['data']['tt_content'][$id]['pid'] = $this->uid_pid;
$urlParams['data']['tt_content'][$id]['sys_language_uid'] = $this->sys_language;
$urlParams['redirect'] = $this->R_URI;
unset($urlParams['defVals']);
$url = $this->uriBuilder->buildUriFromRoute('tce_db', $urlParams);
$aOnClick = 'list_frame.location.href=' . GeneralUtility::quoteJSvalue((string)$url) . '; return false';
}
// Go to DataHandler directly instead of FormEngine - Only when colPos must not be selected
if (($wInfo['saveAndClose'] ?? false) && $onClickEvent !== '') {
$urlParams = [];
$id = StringUtility::getUniqueId('NEW');
parse_str($wInfo['params'], $urlParams);
$urlParams['data']['tt_content'][$id] = $urlParams['defVals']['tt_content'] ?? [];
$urlParams['data']['tt_content'][$id]['colPos'] = $this->colPos;
$urlParams['data']['tt_content'][$id]['pid'] = $this->uid_pid;
$urlParams['data']['tt_content'][$id]['sys_language_uid'] = $this->sys_language;
$urlParams['redirect'] = $this->R_URI;
unset($urlParams['defVals']);
$url = $this->uriBuilder->buildUriFromRoute('tce_db', $urlParams);
$aOnClick = 'list_frame.location.href=' . GeneralUtility::quoteJSvalue((string)$url) . '; return false';
}
$icon = $this->iconFactory->getIcon(
$menuItems[$key]['content'] .= $this->getFluidTemplateObject('MenuItem.html')->assignMultiple([
'onClickEvent' => $onClickEvent,
'aOnClick' => $aOnClick,
'wizardInformation' => $wInfo,
'wizardOnClick' => $wizardOnClick,
'wizardKey' => $wizardKey,
'icon' => $this->iconFactory->getIcon(
($wInfo['iconIdentifier'] ?? ''),
Icon::SIZE_DEFAULT,
($wInfo['iconOverlay'] ?? '')
)->render();
$this->menuItemView->assignMultiple([
'onClickEvent' => $onClickEvent,
'aOnClick' => $aOnClick,
'wizardInformation' => $wInfo,
'icon' => $icon,
'wizardOnClick' => $wizardOnClick,
'wizardKey' => $wizardKey
]);
$menuItems[$key]['content'] .= $this->menuItemView->render();
$cc++;
}
)->render()
])->render();
$cc++;
}
}
$this->view->assign('renderedTabs', $this->moduleTemplate->getDynamicTabMenu(
$menuItems,
'new-content-element-wizard'
));
$this->view->assign('renderedTabs', $this->moduleTemplateFactory->create($request)->getDynamicTabMenu(
$menuItems,
'new-content-element-wizard'
));
// If the user must also select a column:
if (!$onClickEvent) {
$this->definePositionMapEntries();
}
// If the user must also select a column:
if (!$onClickEvent) {
$this->definePositionMapEntries();
}
$this->view->assign('hasAccess', $hasAccess);
}
/**
......@@ -314,23 +295,6 @@ class NewContentElementController
$this->view->assign('posMap', $posMap->printContentElementColumns($this->id, $colPosList, $this->R_URI));
}
/**
* Create the panel of buttons for submitting the form or otherwise perform operations.
*/
protected function getButtons()
{
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
if ($this->R_URI) {
$backButton = $buttonBar->makeLinkButton()
->setHref($this->R_URI)
->setTitle($this->getLanguageService()->getLL('goBack'))
->setIcon($this->iconFactory->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
$buttonBar->addButton($backButton);
}
$cshButton = $buttonBar->makeHelpButton()->setModuleName('xMOD_csh_corebe')->setFieldName('new_ce');
$buttonBar->addButton($cshButton);
}
/**
* Returns the array of elements in the wizard display.
* For the plugin section there is support for adding elements there from a global variable.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment