Skip to content

Commit

Permalink
[TASK] Refactor fluid page module components
Browse files Browse the repository at this point in the history
Refactoring with the goal of:

* Restoring entity-like nature of BackendLayout
* Decreasing coupling between components of the page
  module processing and rendering.

Implements a PageLayoutContext to hold all context-related
objects and methods and passes the context to objects
instead of passing the BackendLayout. Reduces number of
methods on DrawingConfiguration so the configuration object
only holds output- and behavior-related options and does not
hold things like permission checks.

Releases: master
Resolves: #90882
Change-Id: I09f1d97a53a76ea96d6cbc18bb5549127b5a1a71
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64002
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog <look@susi.dev>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Susanne Moog <look@susi.dev>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
NamelessCoder authored and bmack committed Apr 20, 2020
1 parent cb9863f commit be434f2
Show file tree
Hide file tree
Showing 19 changed files with 681 additions and 599 deletions.
31 changes: 19 additions & 12 deletions typo3/sysext/backend/Classes/Controller/PageLayoutController.php
Expand Up @@ -25,6 +25,7 @@
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\BackendLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutContext;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Configuration\Features;
Expand Down Expand Up @@ -160,9 +161,9 @@ class PageLayoutController
protected $uriBuilder;

/**
* @var BackendLayoutView
* @var PageLayoutContext
*/
protected $backendLayouts;
protected $context;

/**
* Injects the request object for the current request or subrequest
Expand All @@ -179,13 +180,18 @@ public function mainAction(ServerRequestInterface $request): ResponseInterface
$this->iconFactory = $this->moduleTemplate->getIconFactory();
$this->uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$this->buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
$this->backendLayouts = GeneralUtility::makeInstance(BackendLayoutView::class);
$this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
// Setting module configuration / page select clause
$this->id = (int)($request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? 0);

// Load page info array
$this->pageinfo = BackendUtility::readPageAccess($this->id, $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW));
$this->context = GeneralUtility::makeInstance(
PageLayoutContext::class,
$this->pageinfo,
GeneralUtility::makeInstance(BackendLayoutView::class)->getBackendLayoutForPage($this->id)
);

/** @var SiteInterface $currentSite */
$currentSite = $request->getAttribute('site');
$this->availableLanguages = $currentSite->getAvailableLanguages($this->getBackendUser(), false, $this->id);
Expand Down Expand Up @@ -547,8 +553,9 @@ function deleteRecord(table,id,url) { //
}
');

$backendLayout = $this->context->getBackendLayout();

// Find backend layout / columns
$backendLayout = $this->backendLayouts->getBackendLayoutForPage($this->id);
if (!empty($backendLayout->getColumnPositionNumbers())) {
$this->colPosList = implode(',', $backendLayout->getColumnPositionNumbers());
}
Expand Down Expand Up @@ -619,26 +626,26 @@ protected function renderContent(): string
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/Paste');
$this->pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');

$backendLayout = $this->backendLayouts->getBackendLayoutForPage((int)$this->id);
$backendLayout = $this->context->getBackendLayout();

$configuration = $backendLayout->getDrawingConfiguration();
$configuration->setPageId($this->id);
$configuration = $this->context->getDrawingConfiguration();
$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);
$configuration->setShowNewContentWizard(empty($this->modTSconfig['properties']['disableNewContentElementWizard']));
$configuration->setSelectedLanguageId((int)$this->MOD_SETTINGS['language']);
if ($this->MOD_SETTINGS['function'] == 2) {
$configuration->setLanguageMode(true);
}
$configuration->setShowNewContentWizard(empty($this->modTSconfig['properties']['disableNewContentElementWizard']));

$numberOfHiddenElements = $this->getNumberOfHiddenElements($configuration->getLanguageColumns());

if (GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('fluidBasedPageModule')) {
$pageLayoutDrawer = $backendLayout->getBackendLayoutRenderer();
$pageLayoutDrawer = $this->context->getBackendLayoutRenderer();

$pageActionsCallback = null;
if ($configuration->isPageEditable()) {
if ($this->context->isPageEditable()) {
$languageOverlayId = 0;
$pageLocalizationRecord = BackendUtility::getRecordLocalization('pages', $this->id, (int)$this->current_sys_language);
if (is_array($pageLocalizationRecord)) {
Expand All @@ -655,7 +662,7 @@ protected function renderContent(): string
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', $pageActionsCallback);
$tableOutput = $pageLayoutDrawer->drawContent();
} else {
$dbList = PageLayoutView::createFromDrawingConfiguration($configuration);
$dbList = PageLayoutView::createFromPageLayoutContext($this->context);
// Setting up the tt_content columns to show
$colList = array_keys($backendLayout->getUsedColumns());
if ($this->colPosList !== '') {
Expand Down
Expand Up @@ -54,7 +54,7 @@ class StandardContentPreviewRenderer implements PreviewRendererInterface, Logger
public function renderPageModulePreviewHeader(GridColumnItem $item): string
{
$record = $item->getRecord();
$itemLabels = $item->getBackendLayout()->getDrawingConfiguration()->getItemLabels();
$itemLabels = $item->getContext()->getItemLabels();

$outHeader = '';

Expand All @@ -81,14 +81,14 @@ public function renderPageModulePreviewContent(GridColumnItem $item): string
$out = '';
$record = $item->getRecord();

$contentTypeLabels = $item->getBackendLayout()->getDrawingConfiguration()->getContentTypeLabels();
$contentTypeLabels = $item->getContext()->getContentTypeLabels();
$languageService = $this->getLanguageService();

$drawItem = true;
$hookPreviewContent = '';
// 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 = PageLayoutView::createFromDrawingConfiguration($item->getBackendLayout()->getDrawingConfiguration());
$pageLayoutView = PageLayoutView::createFromPageLayoutContext($item->getContext());
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) {
Expand Down Expand Up @@ -169,7 +169,7 @@ public function renderPageModulePreviewContent(GridColumnItem $item): string
case 'list':
$hookOut = '';
if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'])) {
$pageLayoutView = PageLayoutView::createFromDrawingConfiguration($item->getBackendLayout()->getDrawingConfiguration());
$pageLayoutView = PageLayoutView::createFromPageLayoutContext($item->getBackendLayout());
$_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']] ??
Expand Down Expand Up @@ -240,7 +240,7 @@ public function renderPageModulePreviewFooter(GridColumnItem $item): string

// Call drawFooter hooks
if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawFooter'])) {
$pageLayoutView = PageLayoutView::createFromDrawingConfiguration($item->getBackendLayout()->getDrawingConfiguration());
$pageLayoutView = PageLayoutView::createFromPageLayoutContext($item->getBackendLayout());
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) {
Expand Down Expand Up @@ -273,7 +273,7 @@ public function wrapPageModulePreview(string $previewHeader, string $previewCont

protected function getProcessedValue(GridColumnItem $item, string $fieldList, array &$info): void
{
$itemLabels = $item->getBackendLayout()->getDrawingConfiguration()->getItemLabels();
$itemLabels = $item->getContext()->getItemLabels();
$record = $item->getRecord();
$fieldArr = explode(',', $fieldList);
foreach ($fieldArr as $field) {
Expand Down
112 changes: 0 additions & 112 deletions typo3/sysext/backend/Classes/View/BackendLayout/BackendLayout.php
Expand Up @@ -15,14 +15,7 @@

namespace TYPO3\CMS\Backend\View\BackendLayout;

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\Grid;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridRow;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\LanguageColumn;
use TYPO3\CMS\Backend\View\BackendLayoutView;
use TYPO3\CMS\Backend\View\Drawing\BackendLayoutRenderer;
use TYPO3\CMS\Backend\View\Drawing\DrawingConfiguration;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand Down Expand Up @@ -67,26 +60,6 @@ class BackendLayout
*/
protected $data;

/**
* @var DrawingConfiguration
*/
protected $drawingConfiguration;

/**
* @var ContentFetcher
*/
protected $contentFetcher;

/**
* @var LanguageColumn[]
*/
protected $languageColumns = [];

/**
* @var RecordRememberer
*/
protected $recordRememberer;

/**
* @param string $identifier
* @param string $title
Expand All @@ -110,9 +83,6 @@ public static function create($identifier, $title, $configuration)
*/
public function __construct($identifier, $title, $configuration)
{
$this->drawingConfiguration = GeneralUtility::makeInstance(DrawingConfiguration::class);
$this->contentFetcher = GeneralUtility::makeInstance(ContentFetcher::class, $this);
$this->recordRememberer = GeneralUtility::makeInstance(RecordRememberer::class);
$this->setIdentifier($identifier);
$this->setTitle($title);
if (is_array($configuration)) {
Expand Down Expand Up @@ -250,90 +220,8 @@ public function getStructure(): array
return $this->structure;
}

/**
* @return LanguageColumn[]
*/
public function getLanguageColumns(): iterable
{
if (empty($this->languageColumns)) {
$availableLanguageColumns = $this->getDrawingConfiguration()->getLanguageColumns();
foreach ($this->getDrawingConfiguration()->getSiteLanguages() as $siteLanguage) {
if (!isset($availableLanguageColumns[$siteLanguage->getLanguageId()])) {
continue;
}
$backendLayout = clone $this;
$backendLayout->getDrawingConfiguration()->setLanguageColumnsPointer($siteLanguage->getLanguageId());
$this->languageColumns[] = GeneralUtility::makeInstance(LanguageColumn::class, $backendLayout, $siteLanguage);
}
}
return $this->languageColumns;
}

public function getGrid(): Grid
{
$grid = GeneralUtility::makeInstance(Grid::class, $this);
foreach ($this->structure['__config']['backend_layout.']['rows.'] ?? [] as $row) {
$rowObject = GeneralUtility::makeInstance(GridRow::class, $this);
foreach ($row['columns.'] as $column) {
$columnObject = GeneralUtility::makeInstance(GridColumn::class, $this, $column);
$rowObject->addColumn($columnObject);
}
$grid->addRow($rowObject);
}
$pageId = $this->drawingConfiguration->getPageId();
$allowInconsistentLanguageHandling = (bool)(BackendUtility::getPagesTSconfig($pageId)['mod.']['web_layout.']['allowInconsistentLanguageHandling'] ?? false);
if (!$allowInconsistentLanguageHandling && $this->getLanguageModeIdentifier() === 'connected') {
$grid->setAllowNewContent(false);
}
return $grid;
}

public function getColumnPositionNumbers(): array
{
return $this->structure['__colPosList'];
}

public function getContentFetcher(): ContentFetcher
{
return $this->contentFetcher;
}

public function setContentFetcher(ContentFetcher $contentFetcher): void
{
$this->contentFetcher = $contentFetcher;
}

public function getDrawingConfiguration(): DrawingConfiguration
{
return $this->drawingConfiguration;
}

public function setDrawingConfiguration(DrawingConfiguration $drawingConfiguration): void
{
$this->drawingConfiguration = $drawingConfiguration;
}

public function getBackendLayoutRenderer(): BackendLayoutRenderer
{
return GeneralUtility::makeInstance(BackendLayoutRenderer::class, $this);
}

public function getRecordRememberer(): RecordRememberer
{
return $this->recordRememberer;
}

public function getLanguageModeIdentifier(): string
{
$contentRecordsPerColumn = $this->contentFetcher->getContentRecordsPerColumn(null, $this->drawingConfiguration->getLanguageColumnsPointer());
$contentRecords = empty($contentRecordsPerColumn) ? [] : array_merge(...$contentRecordsPerColumn);
$translationData = $this->contentFetcher->getTranslationData($contentRecords, $this->drawingConfiguration->getLanguageColumnsPointer());
return $translationData['mode'] ?? '';
}

public function __clone()
{
$this->drawingConfiguration = clone $this->drawingConfiguration;
$this->contentFetcher->setBackendLayout($this);
}
}

0 comments on commit be434f2

Please sign in to comment.