Commit 44c819f8 authored by Marc Willmann's avatar Marc Willmann Committed by Jan Helke
Browse files

[TASK] Fluidification of NewContentElementController

Additionally an unused variable was removed and some
variables have been renamed to a more speaking name.

Resolves: #77801
Releases: master
Change-Id: I242a9f32c80c8702097a2b20ed577db44766902b
Reviewed-on: https://review.typo3.org/49808

Reviewed-by: default avatarDaniel Goerz <ervaude@gmail.com>
Tested-by: default avatarDaniel Goerz <ervaude@gmail.com>
Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Alexander Stehlik's avatarAlexander Stehlik <alexander.stehlik@gmail.com>
Reviewed-by: Philipp Gampe's avatarPhilipp Gampe <philipp.gampe@typo3.org>
Reviewed-by: default avatarJoerg Boesche <typo3@joergboesche.de>
Reviewed-by: default avatarMarkus Sommer <markussom@posteo.de>
Tested-by: default avatarMarkus Sommer <markussom@posteo.de>
Reviewed-by: default avatarMichael Oehlhof <typo3@oehlhof.de>
Tested-by: default avatarMichael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Jan Helke's avatarJan Helke <typo3@helke.de>
Tested-by: Jan Helke's avatarJan Helke <typo3@helke.de>
parent 83c4afc4
......@@ -22,10 +22,10 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\BackendLayoutView;
use TYPO3\CMS\Backend\Wizard\NewContentElementWizardHookInterface;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconRegistry;
use TYPO3\CMS\Core\Service\DependencyOrderingService;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
* Script Class for the New Content element wizard
......@@ -105,11 +105,6 @@ class NewContentElementController extends AbstractModule
*/
protected $pageInfo;
/**
* @var array
*/
protected $elementWrapper;
/**
* @var string
*/
......@@ -120,6 +115,16 @@ class NewContentElementController extends AbstractModule
*/
protected $MCONF;
/**
* @var StandaloneView
*/
protected $view;
/**
* @var StandaloneView
*/
protected $menuItemView;
/**
* Constructor
*/
......@@ -127,6 +132,8 @@ class NewContentElementController extends AbstractModule
{
parent::__construct();
$GLOBALS['SOBE'] = $this;
$this->view = $this->getFluidTemplateObject();
$this->menuItemView = $this->getFluidTemplateObject('MenuItem.html');
$this->init();
}
......@@ -189,9 +196,9 @@ class NewContentElementController extends AbstractModule
*/
public function main()
{
$lang = $this->getLanguageService();
$this->content .= '<form action="" name="editForm" id="NewContentElementController"><input type="hidden" name="defValues" value="" />';
$hasAccess = true;
if ($this->id && $this->access) {
// Init position map object:
$posMap = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\View\ContentCreationPagePositionMap::class);
$posMap->cur_sys_language = $this->sys_language;
......@@ -216,11 +223,9 @@ class NewContentElementController extends AbstractModule
// ***************************
// Creating content
// ***************************
$this->content .= '<h1>' . $lang->getLL('newContentElement') . '</h1>';
// Wizard
$wizardItems = $this->wizardArray();
// Wrapper for wizards
$this->elementWrapper['section'] = ['', ''];
// Hook for manipulating wizardItems, wrapper, onClickEvent etc.
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms']['db_new_content_el']['wizardItemsHook'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms']['db_new_content_el']['wizardItemsHook'] as $classData) {
......@@ -243,69 +248,54 @@ class NewContentElementController extends AbstractModule
}'
);
$iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
// 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 = [];
foreach ($wizardItems as $k => $wInfo) {
$this->view->assign('onClickEvent', $this->onClickEvent);
foreach ($wizardItems as $wizardKey => $wInfo) {
$wizardOnClick = '';
if ($wInfo['header']) {
$menuItems[] = [
'label' => htmlspecialchars($wInfo['header']),
'content' => $this->elementWrapper['section'][0]
'content' => ''
];
$key = count($menuItems) - 1;
} else {
$content = '';
if (!$this->onClickEvent) {
// Radio button:
$oC = 'document.editForm.defValues.value=unescape(' . GeneralUtility::quoteJSvalue(rawurlencode($wInfo['params'])) . ');goToalt_doc();' . (!$this->onClickEvent ? 'window.location.hash=\'#sel2\';' : '');
$content .= '<div class="media-left"><input type="radio" name="tempB" value="' . htmlspecialchars($k) . '" onclick="' . htmlspecialchars($oC) . '" /></div>';
$wizardOnClick = 'document.editForm.defValues.value=unescape(' . GeneralUtility::quoteJSvalue(rawurlencode($wInfo['params'])) . ');goToalt_doc();' . (!$this->onClickEvent ? 'window.location.hash=\'#sel2\';' : '');
// Onclick action for icon/title:
$aOnClick = 'document.getElementsByName(\'tempB\')[' . $cc . '].checked=1;' . $oC . 'return false;';
$aOnClick = 'document.getElementsByName(\'tempB\')[' . $cc . '].checked=1;' . $wizardOnClick . 'return false;';
} else {
$aOnClick = "document.editForm.defValues.value=unescape('" . rawurlencode($wInfo['params']) . "');goToalt_doc();" . (!$this->onClickEvent?"window.location.hash='#sel2';":'');
}
$icon = $this->moduleTemplate->getIconFactory()->getIcon($wInfo['iconIdentifier'])->render();
$menuItems[$key]['content'] .= '
<div class="media">
<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">
' . $content . '
<div class="media-left">
' . $icon . '
</div>
<div class="media-body">
<strong>' . htmlspecialchars($wInfo['title']) . '</strong>' .
'<br />' .
nl2br(htmlspecialchars(trim($wInfo['description']))) .
'</div>
</a>
</div>';
$this->menuItemView->assignMultiple([
'onClickEvent' => $this->onClickEvent,
'aOnClick' => $aOnClick,
'wizardInformation' => $wInfo,
'icon' => $icon,
'wizardOnClick' => $wizardOnClick,
'wizardKey' => $wizardKey
]
);
$menuItems[$key]['content'] .= $this->menuItemView->render();
$cc++;
}
}
// Add closing section-tag
foreach ($menuItems as $key => $val) {
$menuItems[$key]['content'] .= $this->elementWrapper['section'][1];
}
// Add the wizard table to the content, wrapped in tabs
$code = '<p>' . htmlspecialchars($lang->getLL('sel1')) . '</p>' . $this->moduleTemplate->getDynamicTabMenu(
$this->view->assign('renderedTabs', $this->moduleTemplate->getDynamicTabMenu(
$menuItems,
'new-content-element-wizard'
);
$this->content .= !$this->onClickEvent ? '<h2>' . htmlspecialchars($lang->getLL('1_selectType')) . '</h2>' : '';
$this->content .= '<div>' . $code . '</div>';
));
// If the user must also select a column:
if (!$this->onClickEvent) {
// Add anchor "sel2"
$this->content .= '<div><a name="sel2"></a></div>';
// Select position
$code = '<p>' . htmlspecialchars($lang->getLL('sel2')) . '</p>';
// Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
$colPosArray = GeneralUtility::callUserFunction(
......@@ -317,15 +307,15 @@ class NewContentElementController extends AbstractModule
// Removing duplicates, if any
$colPosList = implode(',', array_unique(array_map('intval', $colPosIds)));
// Finally, add the content of the column selector to the content:
$code .= $posMap->printContentElementColumns($this->id, 0, $colPosList, 1, $this->R_URI);
$this->content .= '<h2>' . htmlspecialchars($lang->getLL('2_selectPosition')) . '</h2><div>' . $code . '</div>';
$this->view->assign('posMap', $posMap->printContentElementColumns($this->id, 0, $colPosList, 1, $this->R_URI));
}
} else {
// In case of no access:
$this->content = '';
$this->content .= '<h1>' . $lang->getLL('newContentElement') . '</h1>';
$hasAccess = false;
}
$this->content .= '</form>';
$this->view->assign('hasAccess', $hasAccess);
$this->content = $this->view->render();
// Setting up the buttons and markers for docheader
$this->getButtons();
}
......@@ -579,4 +569,19 @@ class NewContentElementController extends AbstractModule
{
return $GLOBALS['BE_USER'];
}
/**
* returns a new standalone view, shorthand function
*
* @param string $filename
* @return StandaloneView
*/
protected function getFluidTemplateObject(string $filename = 'Main.html'):StandaloneView
{
/** @var StandaloneView $view */
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/NewContentElement/' . $filename));
$view->getRequest()->setControllerExtensionName('Backend');
return $view;
}
}
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:if condition="{hasAccess}">
<f:then>
<f:form action="" name="editForm" id="NewContentElementController">
<f:form.hidden name="defValues" value=""/>
<h1>{f:translate(key: 'LLL:EXT:lang/locallang_misc.xlf:newContentElement')}</h1>
<f:if condition="{onClickEvent} == ''">
<h2>{f:translate(key: 'LLL:EXT:lang/locallang_misc.xlf:1_selectType')}</h2>
</f:if>
<div>
<p>{f:translate(key: 'LLL:EXT:backend/Resources/Private/Language/locallang_db_new_content_el.xlf:sel1')}</p>
{renderedTabs -> f:format.raw()}
</div>
<f:if condition="{onClickEvent} == ''">
<div><a name="sel2"></a></div>
<h2>{f:translate(key: 'LLL:EXT:lang/locallang_misc.xlf:2_selectPosition') -> f:format.htmlspecialchars()}</h2>
<div>
<p>{f:translate(key: 'LLL:EXT:backend/Resources/Private/Language/locallang_db_new_content_el.xlf:sel2') ->
f:format.htmlspecialchars()}</p>
{posMap -> f:format.raw()}
</div>
</f:if>
</f:form>
</f:then>
<f:else>
<h1>{f:translate(key: 'LLL:EXT:lang/locallang_misc.xlf:newContentElement')}</h1>
</f:else>
</f:if>
</html>
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<div class="media">
<a href="#" onclick="{aOnClick -> f:format.htmlspecialchars()}">
<f:if condition="{onClickEvent} == ''">
<div class="media-left">
<input type="radio" name="tempB" value="{wizardKey -> f:format.htmlspecialchars()}" onclick="{wizardOnClick -> f:format.htmlspecialchars()}"/>
</div>
</f:if>
{content -> f:format.raw()}
<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>
</a>
</div>
</html>
Supports Markdown
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