Commit 2cad696a authored by Benni Mack's avatar Benni Mack Committed by Georg Ringer
Browse files

[TASK] Clean up drawing configuration for Fluid-based page module

PageLayoutView now builds a "Configuration" model for both variants
PageLayoutView is not set up via the DrawingConfiguration object,
which is now based on a factory method.

PageLayoutController now injects all RequireJS modules in one place,
and not in fluid anymore.

Minor bugs regarding "getLanguageColumns" are fixed.

The main "pageLayoutConfiguration" is now injected and used where it does not
differ from the backend module configuration.

Resolves: #90858
Releases: master
Change-Id: I16925488e0bff75ec73f9dddbfd047cca3bd2da1
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63938

Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
parent c4c6dd6f
......@@ -23,6 +23,7 @@ use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\BackendLayoutView;
use TYPO3\CMS\Backend\View\Drawing\DrawingConfiguration;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Configuration\Features;
......@@ -610,23 +611,31 @@ class PageLayoutController
protected function renderContent(): string
{
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Localization');
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/DragDrop');
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/Paste');
$this->pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
if (GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('fluidBasedPageModule')) {
$backendLayout = $this->backendLayouts->getBackendLayoutForPage((int)$this->id);
$configuration = $backendLayout->getDrawingConfiguration();
$configuration->setPageId($this->id);
$configuration->setDefaultLanguageBinding(!empty($this->modTSconfig['properties']['defLangBinding']));
$configuration->setActiveColumns(GeneralUtility::trimExplode(',', $this->activeColPosList));
$configuration->setShowHidden((bool)$this->MOD_SETTINGS['tt_content_showHidden']);
$configuration->setLanguageColumns(array_combine(array_keys($this->MOD_MENU['language']), array_keys($this->MOD_MENU['language'])));
$configuration->setLanguageColumnsPointer((int)$this->current_sys_language);
if ($this->MOD_SETTINGS['function'] == 2) {
$configuration->setLanguageMode($this->MOD_SETTINGS['function'] == 2);
}
$configuration = GeneralUtility::makeInstance(DrawingConfiguration::class);
$configuration->setPageId($this->id);
$configuration->setDefaultLanguageBinding(!empty($this->modTSconfig['properties']['defLangBinding']));
$configuration->setActiveColumns(GeneralUtility::trimExplode(',', $this->activeColPosList));
$configuration->setShowHidden((bool)$this->MOD_SETTINGS['tt_content_showHidden']);
$configuration->setLanguageColumns($this->MOD_MENU['language']);
$configuration->setLanguageColumnsPointer((int)$this->current_sys_language);
if ($this->MOD_SETTINGS['function'] == 2) {
$configuration->setLanguageMode(true);
}
$configuration->setShowNewContentWizard(empty($this->modTSconfig['properties']['disableNewContentElementWizard']));
$numberOfHiddenElements = $this->getNumberOfHiddenElements($configuration->getLanguageColumns());
$backendLayout = $this->backendLayouts->getBackendLayoutForPage((int)$this->id);
$backendLayout->setDrawingConfiguration($configuration);
if (GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('fluidBasedPageModule')) {
$pageLayoutDrawer = $backendLayout->getBackendLayoutRenderer();
$configuration->setShowNewContentWizard(empty($this->modTSconfig['properties']['disableNewContentElementWizard']));
$pageActionsCallback = null;
if ($configuration->isPageEditable()) {
......@@ -644,63 +653,29 @@ class PageLayoutController
}';
}
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', $pageActionsCallback);
$numberOfHiddenElements = $this->getNumberOfHiddenElements($configuration->getLanguageColumns());
$tableOutput = $pageLayoutDrawer->drawContent();
} else {
$dbList = GeneralUtility::makeInstance(PageLayoutView::class);
$dbList->doEdit = $this->isContentEditable($this->current_sys_language);
$dbList->option_newWizard = empty($this->modTSconfig['properties']['disableNewContentElementWizard']);
$dbList->defLangBinding = !empty($this->modTSconfig['properties']['defLangBinding']);
$tcaItems = $this->backendLayouts->getColPosListItemsParsed($this->id);
$numberOfHiddenElements = $this->getNumberOfHiddenElements(is_array($dbList->tt_contentConfig['languageCols']) ? $dbList->tt_contentConfig['languageCols'] : []);
// Setting up the tt_content columns to show:
if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
$colList = [];
foreach ($tcaItems as $temp) {
$colList[] = $temp[1];
}
} else {
// ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
$colList = ['1', '0', '2', '3'];
}
$dbList = PageLayoutView::createFromDrawingConfiguration($configuration);
// Setting up the tt_content columns to show
$colList = array_keys($backendLayout->getUsedColumns());
if ($this->colPosList !== '') {
$colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
}
// The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
$dbList->tt_contentConfig['cols'] = implode(',', $colList);
$dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
$dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
$dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
// If the function menu is set to "Language":
if ($this->MOD_SETTINGS['function'] == 2) {
$dbList->tt_contentConfig['languageMode'] = 1;
$dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
$dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
}
$tableOutput = $dbList->getTable_tt_content($this->id);
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Localization');
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/DragDrop');
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/Paste');
}
$this->pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
$h_func_b = '';
if ($this->getBackendUser()->check('tables_select', 'tt_content')) {
if ($this->getBackendUser()->check('tables_select', 'tt_content') && $numberOfHiddenElements > 0) {
// Toggle hidden ContentElements
if ($numberOfHiddenElements > 0) {
$h_func_b = '
<div class="checkbox">
<label for="checkTt_content_showHidden">
<input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />
' . htmlspecialchars($this->getLanguageService()->getLL('hiddenCE')) . ' (<span class="t3js-hidden-counter">' . $numberOfHiddenElements . '</span>)
</label>
</div>';
}
$tableOutput .= '
<div class="checkbox">
<label for="checkTt_content_showHidden">
<input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />
' . htmlspecialchars($this->getLanguageService()->getLL('hiddenCE')) . ' (<span class="t3js-hidden-counter">' . $numberOfHiddenElements . '</span>)
</label>
</div>';
}
$tableOutput .= $h_func_b;
// Init the content
$content = '';
......
......@@ -20,7 +20,6 @@ use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
use TYPO3\CMS\Backend\View\Drawing\DrawingConfiguration;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawFooterHookInterface;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
......@@ -150,7 +149,7 @@ class StandardContentPreviewRenderer implements PreviewRendererInterface, Logger
case 'list':
$hookOut = '';
if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'])) {
$pageLayoutView = $this->createEmulatedPageLayoutViewFromDrawingConfiguration($item->getBackendLayout()->getDrawingConfiguration());
$pageLayoutView = PageLayoutView::createFromDrawingConfiguration($item->getBackendLayout()->getDrawingConfiguration());
$_params = ['pObj' => &$pageLayoutView, 'row' => $record];
foreach (
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$record['list_type']] ??
......@@ -221,7 +220,7 @@ class StandardContentPreviewRenderer implements PreviewRendererInterface, Logger
// Call drawFooter hooks
if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawFooter'])) {
$pageLayoutView = $this->createEmulatedPageLayoutViewFromDrawingConfiguration($item->getBackendLayout()->getDrawingConfiguration());
$pageLayoutView = PageLayoutView::createFromDrawingConfiguration($item->getBackendLayout()->getDrawingConfiguration());
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawFooter'] ?? [] as $className) {
$hookObject = GeneralUtility::makeInstance($className);
if (!$hookObject instanceof PageLayoutViewDrawFooterHookInterface) {
......@@ -251,7 +250,7 @@ class StandardContentPreviewRenderer implements PreviewRendererInterface, Logger
// Hook: Render an own preview of a record
if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'])) {
$pageLayoutView = $this->createEmulatedPageLayoutViewFromDrawingConfiguration($item->getBackendLayout()->getDrawingConfiguration());
$pageLayoutView = PageLayoutView::createFromDrawingConfiguration($item->getBackendLayout()->getDrawingConfiguration());
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'] ?? [] as $className) {
$hookObject = GeneralUtility::makeInstance($className);
if (!$hookObject instanceof PageLayoutViewDrawItemHookInterface) {
......@@ -419,27 +418,6 @@ class StandardContentPreviewRenderer implements PreviewRendererInterface, Logger
return $linkText;
}
protected function createEmulatedPageLayoutViewFromDrawingConfiguration(DrawingConfiguration $drawingConfiguration): PageLayoutView
{
$pageLayoutView = GeneralUtility::makeInstance(PageLayoutView::class);
$pageLayoutView->id = $drawingConfiguration->getPageId();
$pageLayoutView->pageRecord = $drawingConfiguration->getPageRecord();
$pageLayoutView->option_newWizard = $drawingConfiguration->getShowNewContentWizard();
$pageLayoutView->defLangBinding = $drawingConfiguration->getDefaultLanguageBinding();
$pageLayoutView->tt_contentConfig['cols'] = implode(',', $drawingConfiguration->getActiveColumns());
$pageLayoutView->tt_contentConfig['activeCols'] = implode(',', $drawingConfiguration->getActiveColumns());
$pageLayoutView->tt_contentConfig['showHidden'] = $drawingConfiguration->getShowHidden();
$pageLayoutView->tt_contentConfig['sys_language_uid'] = $drawingConfiguration->getLanguageColumnsPointer();
if ($drawingConfiguration->getLanguageMode()) {
$pageLayoutView->tt_contentConfig['languageMode'] = 1;
$pageLayoutView->tt_contentConfig['languageCols'] = $drawingConfiguration->getLanguageColumns();
$pageLayoutView->tt_contentConfig['languageColsPointer'] = $drawingConfiguration->getLanguageColumnsPointer();
}
$pageLayoutView->CType_labels = $drawingConfiguration->getContentTypeLabels();
$pageLayoutView->itemLabels = $drawingConfiguration->getItemLabels();
return $pageLayoutView;
}
protected function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
......
......@@ -255,8 +255,9 @@ class BackendLayout
public function getLanguageColumns(): iterable
{
if (empty($this->languageColumns)) {
$availableLanguageColumns = $this->getDrawingConfiguration()->getLanguageColumns();
foreach ($this->getDrawingConfiguration()->getSiteLanguages() as $siteLanguage) {
if (!in_array($siteLanguage->getLanguageId(), $this->getDrawingConfiguration()->getLanguageColumns())) {
if (!isset($availableLanguageColumns[$siteLanguage->getLanguageId()])) {
continue;
}
$backendLayout = clone $this;
......@@ -306,6 +307,11 @@ class BackendLayout
return $this->drawingConfiguration;
}
public function setDrawingConfiguration(DrawingConfiguration $drawingConfiguration): void
{
$this->drawingConfiguration = $drawingConfiguration;
}
public function getBackendLayoutRenderer(): BackendLayoutRenderer
{
return GeneralUtility::makeInstance(BackendLayoutRenderer::class, $this);
......
......@@ -92,6 +92,7 @@ class BackendLayoutRenderer
*/
public function drawContent(bool $renderUnused = true): string
{
$this->view->assign('pageLayoutConfiguration', $this->backendLayout->getDrawingConfiguration());
$this->view->assign('hideRestrictedColumns', (bool)(BackendUtility::getPagesTSconfig($this->backendLayout->getDrawingConfiguration()->getPageId())['mod.']['web_layout.']['hideRestrictedCols'] ?? false));
if (!$this->backendLayout->getDrawingConfiguration()->getLanguageMode()) {
$this->view->assign('grid', $this->backendLayout->getGrid());
......
......@@ -53,6 +53,7 @@ class DrawingConfiguration
protected $languageMode = false;
/**
* Key => "Language ID", Value "Label of language"
* @var array
*/
protected $languageColumns = [];
......@@ -124,8 +125,8 @@ class DrawingConfiguration
public function getLanguageColumns(): array
{
if ($this->languageColumnsPointer) {
return [0 => 0, $this->languageColumnsPointer => $this->languageColumnsPointer];
if (empty($this->languageColumns)) {
return [0 => 'Default'];
}
return $this->languageColumns;
}
......
......@@ -23,6 +23,7 @@ use TYPO3\CMS\Backend\Clipboard\Clipboard;
use TYPO3\CMS\Backend\Controller\Page\LocalizationController;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\Drawing\DrawingConfiguration;
use TYPO3\CMS\Backend\View\Event\AfterSectionMarkupGeneratedEvent;
use TYPO3\CMS\Backend\View\Event\BeforeSectionMarkupGeneratedEvent;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
......@@ -205,6 +206,34 @@ class PageLayoutView implements LoggerAwareInterface
$this->eventDispatcher = $eventDispatcher;
}
/**
* @param DrawingConfiguration $drawingConfiguration
* @return PageLayoutView
* @internal
*/
public static function createFromDrawingConfiguration(DrawingConfiguration $drawingConfiguration): PageLayoutView
{
/** @var PageLayoutView $pageLayoutView */
$pageLayoutView = GeneralUtility::makeInstance(self::class);
$pageLayoutView->id = $drawingConfiguration->getPageId();
$pageLayoutView->pageRecord = $drawingConfiguration->getPageRecord();
$pageLayoutView->option_newWizard = $drawingConfiguration->getShowNewContentWizard();
$pageLayoutView->defLangBinding = $drawingConfiguration->getDefaultLanguageBinding();
$pageLayoutView->tt_contentConfig['cols'] = implode(',', $drawingConfiguration->getActiveColumns());
$pageLayoutView->tt_contentConfig['activeCols'] = implode(',', $drawingConfiguration->getActiveColumns());
$pageLayoutView->tt_contentConfig['showHidden'] = $drawingConfiguration->getShowHidden();
$pageLayoutView->tt_contentConfig['sys_language_uid'] = $drawingConfiguration->getLanguageColumnsPointer();
if ($drawingConfiguration->getLanguageMode()) {
$pageLayoutView->tt_contentConfig['languageMode'] = 1;
$pageLayoutView->tt_contentConfig['languageCols'] = $drawingConfiguration->getLanguageColumns();
$pageLayoutView->tt_contentConfig['languageColsPointer'] = $drawingConfiguration->getLanguageColumnsPointer();
}
$pageLayoutView->doEdit = $pageLayoutView->isContentEditable($drawingConfiguration->getLanguageColumnsPointer());
$pageLayoutView->CType_labels = $drawingConfiguration->getContentTypeLabels();
$pageLayoutView->itemLabels = $drawingConfiguration->getItemLabels();
return $pageLayoutView;
}
protected function initialize()
{
$this->resolveSiteLanguages($this->id);
......
......@@ -26,8 +26,8 @@
</f:if>
</div>
<f:if condition="{allowEditContent} && {column.contentEditable} && {grid.allowNewContent}">
<div class="t3-page-ce t3js-page-ce" data-page="{column.backendLayout.drawingConfiguration.pageId}" id="{column.uniqueId}">
<div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-{column.columnNumber}-page-{column.backendLayout.drawingConfiguration.pageId}-{column.uniqueId}">
<div class="t3-page-ce t3js-page-ce" data-page="{pageLayoutConfiguration.pageId}" id="{column.uniqueId}">
<div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-{column.columnNumber}-page-{pageLayoutConfiguration.pageId}-{column.uniqueId}">
<a href="{column.newContentUrl}" title="{newContentTitle}" data-title="{newContentTitle}"
class="btn btn-default btn-sm t3js-toggle-new-content-element-wizard">
<core:icon identifier="actions-add" />
......
<f:if condition="{backendLayout.drawingConfiguration.newLanguageOptions}">
<f:if condition="{pageLayoutConfiguration.newLanguageOptions}">
<div class="form-inline form-inline-spaced">
<div class="form-group">
<select class="form-control input-sm" name="createNewLanguage" onchange="window.location.href=this.options[this.selectedIndex].value">'
<f:for each="{backendLayout.drawingConfiguration.newLanguageOptions}" as="languageName" key="url">
<f:for each="{pageLayoutConfiguration.newLanguageOptions}" as="languageName" key="url">
<option value="{url}">{languageName}</option>
</f:for>
</select>
......
......@@ -18,7 +18,7 @@
</div>
</div>
<f:if condition="{allowEditContent} && {item.column.contentEditable} && {grid.allowNewContent}">
<div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-{item.column.columnNumber}-page-{item.column.backendLayout.drawingConfiguration.pageId}-{item.column.uniqueId}">
<div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-{item.column.columnNumber}-page-{pageLayoutConfiguration.pageId}-{item.column.uniqueId}">
<a href="{item.newContentAfterUrl}" title="{item.newContentAfterLinkTitle}" data-title="{item.newContentAfterLinkTitle}" class="btn btn-default btn-sm t3js-toggle-new-content-element-wizard">
<core:icon identifier="actions-add" />
{item.newContentAfterTitle}
......
{namespace be=TYPO3\CMS\Backend\ViewHelpers}
<f:be.pageRenderer includeRequireJsModules="{
0: 'TYPO3/CMS/Backend/Tooltip',
1: 'TYPO3/CMS/Backend/Localization',
2: 'TYPO3/CMS/Backend/LayoutModule/DragDrop',
3: 'TYPO3/CMS/Backend/Modal',
4: 'TYPO3/CMS/Backend/LayoutModule/Paste'
}" />
<f:if condition="{backendLayout.drawingConfiguration.languageMode}">
<f:if condition="{pageLayoutConfiguration.languageMode}">
<f:then>
<f:render partial="PageLayout/LanguageColumns" arguments="{_all}" />
</f:then>
......
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