Skip to content

Commit

Permalink
[!!!][TASK] New Content Block folder structure (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhovratov authored Oct 8, 2024
1 parent 4b2a8f3 commit d96cbc5
Show file tree
Hide file tree
Showing 185 changed files with 629 additions and 462 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file datatype="plaintext" original="Labels.xlf" source-language="en" date="2024-01-29T13:43:08+00:00" product-name="example/accordion">
<file datatype="plaintext" original="labels.xlf" source-language="en" date="2024-09-20T23:35:32+00:00" product-name="example/accordion">
<header/>
<body>
<trans-unit id="title" resname="title">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
data-namespace-typo3-fluid="true"
>

<f:asset.css identifier="cbAccordionCssBackend" href="{cb:assetPath()}/EditorPreview.css"/>
<f:asset.css identifier="cbAccordionCssBackend" href="{cb:assetPath()}/preview.css"/>

<div class="cb-accordion">
<f:for each="{data.accordion_item}" as="item">
<be:link.editRecord uid="{item.uid}" table="{item.tableName}">
<be:link.editRecord uid="{item.uid}" table="{item.mainType}">
<div class="accordion-item">
{item.text}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
data-namespace-typo3-fluid="true"
>

<f:asset.css identifier="cbAccordionCssFrontend" href="{cb:assetPath()}/Frontend.css"/>
<f:asset.script identifier="cbAccordionJsFrontend" src="{cb:assetPath()}/Frontend.js"/>
<f:asset.css identifier="cbAccordionCssFrontend" href="{cb:assetPath()}/frontend.css"/>
<f:asset.script identifier="cbAccordionJsFrontend" src="{cb:assetPath()}/frontend.js"/>

<div class="cb-accordion">
<f:for each="{data.accordion_item}" as="item">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file datatype="plaintext" original="Labels.xlf" source-language="en" date="2024-01-29T13:43:08+00:00" product-name="example/card-group">
<file datatype="plaintext" original="labels.xlf" source-language="en" date="2024-09-20T23:35:32+00:00" product-name="example/card-group">
<header/>
<body>
<trans-unit id="title" resname="title">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
data-namespace-typo3-fluid="true"
>

<f:asset.css identifier="cbCardGroupCssBackend" href="{cb:assetPath()}/EditorPreview.css"/>
<f:asset.css identifier="cbCardGroupCssBackend" href="{cb:assetPath()}/preview.css"/>

<div class="cb-card-group">
<f:if condition="{data.card_group_item}">
<div class="card-group-element card-group-element-align-{data.settings.alignment} card-group-element-columns-{data.settings.row_items}">
<f:for each="{data.card_group_item}" as="item" iteration="iteration">

<div class="card-group-element-item">
<be:link.editRecord uid="{item.uid}" table="{item.tableName}">
<be:link.editRecord uid="{item.uid}" table="{item.mainType}">
<div class="card">
<f:if condition="{item.image.0}">
<div class="card-img-top">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
data-namespace-typo3-fluid="true"
>

<f:asset.css identifier="cbCardGroupCssFrontend" href="{cb:assetPath()}/Frontend.css"/>
<f:asset.css identifier="cbCardGroupCssFrontend" href="{cb:assetPath()}/frontend.css"/>

<div class="cb-card-group">
<f:if condition="{data.card_group_item}">
Expand All @@ -16,7 +16,7 @@
<f:if condition="{item.image.0}">
<div class="card-img-top">
<f:render partial="LinkWrap" arguments="{link: item.link, link_title: item.title}" contentAs="content">
<f:image src="{item.image.0.uid}" treatIdAsReference="1"/>
<f:image image="{item.image.0}"/>
</f:render>
</div>
</f:if>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file datatype="plaintext" original="Labels.xlf" source-language="en" date="2024-01-29T15:36:43+00:00" product-name="example/cta">
<file datatype="plaintext" original="labels.xlf" source-language="en" date="2024-09-20T23:35:32+00:00" product-name="example/cta">
<header/>
<body>
<trans-unit id="title" resname="title">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
data-namespace-typo3-fluid="true"
>

<f:asset.css identifier="cbCtaCssBackend" href="{cb:assetPath()}/EditorPreview.css"/>
<f:asset.css identifier="cbCtaCssBackend" href="{cb:assetPath()}/preview.css"/>

<div class="cb-cta">
<h2>{data.header}</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
data-namespace-typo3-fluid="true"
>

<f:asset.css identifier="cbCtaCssFrontend" href="{cb:assetPath()}/Frontend.css"/>
<f:asset.css identifier="cbCtaCssFrontend" href="{cb:assetPath()}/frontend.css"/>

<div class="cb-cta">
<f:if condition="{data.background_image}">
<f:variable name="backgroundUrl">{f:uri.image(src:'{data.background_image.0.uid}', treatIdAsReference:1)}</f:variable>
<f:variable name="backgroundUrl">{f:uri.image(image: data.background_image.0)}</f:variable>
<f:variable name="elementBgId">cb-cta-bg-{data.uid}</f:variable>
<f:variable name="backgroundImageStyles">{elementBgId} { background-image: url({backgroundUrl});}</f:variable>
<f:asset.css identifier="cb-cta-bg-{data.uid}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file datatype="plaintext" original="Labels.xlf" source-language="en" date="2024-05-01T19:02:23+00:00" product-name="example/icon-group">
<file datatype="plaintext" original="labels.xlf" source-language="en" date="2024-09-20T23:35:32+00:00" product-name="example/icon-group">
<header/>
<body>
<trans-unit id="title" resname="title">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
data-namespace-typo3-fluid="true"
>

<f:asset.css identifier="cbIconGroupCssBackend" href="{cb:assetPath()}/EditorPreview.css"/>
<f:asset.css identifier="cbIconGroupCssBackend" href="{cb:assetPath()}/preview.css"/>

<div class="cb-icon-group">
<f:if condition="{data.icon_group_item}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
data-namespace-typo3-fluid="true"
>

<f:asset.css identifier="cbIconGroupCssFrontend" href="{cb:assetPath()}/Frontend.css"/>
<f:asset.css identifier="cbIconGroupCssFrontend" href="{cb:assetPath()}/frontend.css"/>

<div class="cb-icon-group">
<f:if condition="{data.icon_group_item}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file datatype="plaintext" original="Labels.xlf" source-language="en" date="2024-01-29T13:43:08+00:00" product-name="example/imageslider">
<file datatype="plaintext" original="labels.xlf" source-language="en" date="2024-09-20T23:35:32+00:00" product-name="example/imageslider">
<header/>
<body>
<trans-unit id="title" resname="title">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
data-namespace-typo3-fluid="true"
>

<f:asset.css identifier="cbImagesliderCssBackend" href="{cb:assetPath()}/EditorPreview.css"/>
<f:asset.css identifier="cbImagesliderCssBackend" href="{cb:assetPath()}/preview.css"/>

<div class="cb-imageslider">
<f:for each="{data.assets}" as="asset">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<f:asset.css identifier="cbImagesliderCssSwiffySlider" href="{cb:assetPath()}/Library/SwiffySlider/swiffy-slider.min.css"/>
<f:asset.script identifier="cbImagesliderJsSwiffySlider" src="{cb:assetPath()}/Library/SwiffySlider/swiffy-slider.min.js"/>
<f:asset.css identifier="cbImagesliderCssFrontend" href="{cb:assetPath()}/Frontend.css"/>
<f:asset.css identifier="cbImagesliderCssFrontend" href="{cb:assetPath()}/frontend.css"/>

<div class="cb-imageslider">
<div class="swiffy-slider slider-item-ratio slider-item-ratio-16x9 slider-nav-animation slider-nav-animation-fadein slider-item-first-visible" id="swiffy-animation">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file datatype="plaintext" original="Labels.xlf" source-language="en" date="2024-01-29T13:43:08+00:00" product-name="example/tabs">
<file datatype="plaintext" original="labels.xlf" source-language="en" date="2024-09-20T23:35:32+00:00" product-name="example/tabs">
<header/>
<body>
<trans-unit id="title" resname="title">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
data-namespace-typo3-fluid="true"
>

<f:asset.css identifier="cbTabsCssFrontend" href="{cb:assetPath()}/Frontend.css"/>
<f:asset.script identifier="cbTabsJsFrontend" src="{cb:assetPath()}/Frontend.js"/>
<f:asset.css identifier="cbTabsCssFrontend" href="{cb:assetPath()}/frontend.css"/>
<f:asset.script identifier="cbTabsJsFrontend" src="{cb:assetPath()}/frontend.js"/>

<div class="cb-tabs">
<div class="tab">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file datatype="plaintext" original="Labels.xlf" source-language="en" date="2024-01-30T18:23:22+00:00" product-name="example/text">
<file datatype="plaintext" original="labels.xlf" source-language="en" date="2024-09-20T23:35:32+00:00" product-name="example/text">
<header/>
<body>
<trans-unit id="title" resname="title">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file datatype="plaintext" original="Labels.xlf" source-language="en" date="2024-01-29T13:43:08+00:00" product-name="example/example-page-type">
<file datatype="plaintext" original="labels.xlf" source-language="en" date="2024-09-20T23:35:32+00:00" product-name="example/example-page-type">
<header/>
<body>
<trans-unit id="title" resname="title">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file datatype="plaintext" original="Labels.xlf" source-language="en" date="2024-01-29T13:43:08+00:00" product-name="hov/notype">
<file datatype="plaintext" original="labels.xlf" source-language="en" date="2024-09-20T23:35:32+00:00" product-name="hov/notype">
<header/>
<body>
<trans-unit id="title" resname="title">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file datatype="plaintext" original="Labels.xlf" source-language="en" date="2024-01-29T13:43:08+00:00" product-name="hov/record1">
<file datatype="plaintext" original="labels.xlf" source-language="en" date="2024-09-20T23:35:32+00:00" product-name="hov/record1">
<header/>
<body>
<trans-unit id="title" resname="title">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file datatype="plaintext" original="Labels.xlf" source-language="en" date="2024-01-29T13:43:08+00:00" product-name="hov/record2">
<file datatype="plaintext" original="labels.xlf" source-language="en" date="2024-09-20T23:35:32+00:00" product-name="hov/record2">
<header/>
<body>
<trans-unit id="title" resname="title">
Expand Down
34 changes: 20 additions & 14 deletions Classes/Backend/Preview/PageLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace TYPO3\CMS\ContentBlocks\Backend\Preview;

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Controller\Event\ModifyPageLayoutContentEvent;
use TYPO3\CMS\Backend\Module\ModuleData;
use TYPO3\CMS\Backend\Utility\BackendUtility;
Expand All @@ -28,7 +29,9 @@
use TYPO3\CMS\ContentBlocks\Utility\ContentBlockPathUtility;
use TYPO3\CMS\Core\Domain\RecordFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Core\View\ViewFactoryData;
use TYPO3\CMS\Core\View\ViewFactoryInterface;
use TYPO3\CMS\Core\View\ViewInterface;

/**
* @internal Not part of TYPO3's public API.
Expand All @@ -42,6 +45,7 @@ public function __construct(
protected ContentBlockDataDecorator $contentBlockDataDecorator,
protected RootPathsSettings $rootPathsSettings,
protected ContentTypeResolver $contentTypeResolver,
protected ViewFactoryInterface $viewFactory,
) {}

public function __invoke(ModifyPageLayoutContentEvent $event): void
Expand Down Expand Up @@ -74,22 +78,24 @@ public function __invoke(ModifyPageLayoutContentEvent $event): void
return;
}
$contentBlockData = $this->contentBlockDataDecorator->decorate($resolvedRecord);
$view = $this->createView($contentTypeDefinition, $pageUid);
$view->setRequest($request);
$view = $this->createView($contentTypeDefinition, $pageUid, $request);
$view->assign('data', $contentBlockData);
$renderedView = (string)$view->render();
$renderedView = $view->render();
$event->addHeaderContent($renderedView);
}

protected function createView(ContentTypeInterface $contentTypeDefinition, int $pageUid): StandaloneView
protected function createView(ContentTypeInterface $contentTypeDefinition, int $pageUid, ServerRequestInterface $request): ViewInterface
{
$contentBlockPrivatePath = $this->getContentBlockPrivatePath($contentTypeDefinition);
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setLayoutRootPaths($this->getContentBlocksLayoutRootPaths($contentBlockPrivatePath, $pageUid));
$view->setPartialRootPaths($this->getContentBlocksPartialRootPaths($contentBlockPrivatePath, $pageUid));
$view->setTemplateRootPaths([$contentBlockPrivatePath]);
$view->setTemplate(ContentBlockPathUtility::getBackendPreviewFileNameWithoutExtension());
return $view;
$layoutRootPaths = $this->getContentBlocksLayoutRootPaths($contentBlockPrivatePath, $pageUid);
$partialRootPaths = $this->getContentBlocksPartialRootPaths($contentBlockPrivatePath, $pageUid);
$viewData = new ViewFactoryData(
partialRootPaths: $partialRootPaths,
layoutRootPaths: $layoutRootPaths,
templatePathAndFilename: $contentBlockPrivatePath . '/' . ContentBlockPathUtility::getBackendPreviewFileName(),
request: $request,
);
return $this->viewFactory->create($viewData);
}

/**
Expand All @@ -98,7 +104,7 @@ protected function createView(ContentTypeInterface $contentTypeDefinition, int $
protected function getContentBlocksPartialRootPaths(string $contentBlockPrivatePath, int $pageUid): array
{
$partialRootPaths = $this->rootPathsSettings->getContentBlocksPartialRootPaths($pageUid);
$partialRootPaths[] = $contentBlockPrivatePath . '/Partials/';
$partialRootPaths[] = $contentBlockPrivatePath . '/partials/';
return $partialRootPaths;
}

Expand All @@ -108,14 +114,14 @@ protected function getContentBlocksPartialRootPaths(string $contentBlockPrivateP
protected function getContentBlocksLayoutRootPaths(string $contentBlockPrivatePath, int $pageUid): array
{
$partialRootPaths = $this->rootPathsSettings->getContentBlocksLayoutRootPaths($pageUid);
$partialRootPaths[] = $contentBlockPrivatePath . '/Layouts';
$partialRootPaths[] = $contentBlockPrivatePath . '/layouts';
return $partialRootPaths;
}

protected function getContentBlockPrivatePath(ContentTypeInterface $contentTypeDefinition): string
{
$contentBlockExtPath = $this->getEditorPreviewExtPath($contentTypeDefinition);
$contentBlockPrivatePath = $contentBlockExtPath . '/' . ContentBlockPathUtility::getPrivateFolder();
$contentBlockPrivatePath = $contentBlockExtPath . '/' . ContentBlockPathUtility::getTemplatesFolder();
return $contentBlockPrivatePath;
}

Expand Down
31 changes: 18 additions & 13 deletions Classes/Backend/Preview/PreviewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
use TYPO3\CMS\ContentBlocks\Utility\ContentBlockPathUtility;
use TYPO3\CMS\Core\Domain\RecordFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Core\View\ViewFactoryData;
use TYPO3\CMS\Core\View\ViewFactoryInterface;
use TYPO3\CMS\Core\View\ViewInterface;

/**
* Sets up Fluid and applies the same DataProcessor as the frontend to the data record.
Expand All @@ -41,6 +43,7 @@ public function __construct(
protected ContentBlockRegistry $contentBlockRegistry,
protected ContentBlockDataDecorator $contentBlockDataDecorator,
protected RootPathsSettings $rootPathsSettings,
protected ViewFactoryInterface $viewFactory,
) {}

public function renderPageModulePreviewContent(GridColumnItem $item): string
Expand All @@ -58,7 +61,7 @@ public function renderPageModulePreviewContent(GridColumnItem $item): string
$contentTypeDefinition = $contentTypeCollection->getFirst();
}
$contentBlockExtPath = $this->contentBlockRegistry->getContentBlockExtPath($contentTypeDefinition->getName());
$contentBlockPrivatePath = $contentBlockExtPath . '/' . ContentBlockPathUtility::getPrivateFolder();
$contentBlockPrivatePath = $contentBlockExtPath . '/' . ContentBlockPathUtility::getTemplatesFolder();

// Fall back to standard preview rendering if EditorPreview.html does not exist.
$editorPreviewExtPath = $contentBlockExtPath . '/' . ContentBlockPathUtility::getBackendPreviewPath();
Expand All @@ -71,23 +74,25 @@ public function renderPageModulePreviewContent(GridColumnItem $item): string
$data = $this->contentBlockDataDecorator->decorate($resolvedRecord, $item->getContext());
$view = $this->createView($contentBlockPrivatePath, $request, $item);
$view->assign('data', $data);
$result = (string)$view->render();
$result = $view->render();
return $result;
}

protected function createView(
string $contentBlockPrivatePath,
ServerRequestInterface $request,
GridColumnItem $item
): StandaloneView {
): ViewInterface {
$pageUid = $item->getContext()->getPageId();
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setLayoutRootPaths($this->getContentBlocksLayoutRootPaths($contentBlockPrivatePath, $pageUid));
$view->setPartialRootPaths($this->getContentBlocksPartialRootPaths($contentBlockPrivatePath, $pageUid));
$view->setTemplateRootPaths([$contentBlockPrivatePath]);
$view->setTemplate(ContentBlockPathUtility::getBackendPreviewFileNameWithoutExtension());
$view->setRequest($request);
return $view;
$partialRootPaths = $this->getContentBlocksPartialRootPaths($contentBlockPrivatePath, $pageUid);
$layoutRootPaths = $this->getContentBlocksLayoutRootPaths($contentBlockPrivatePath, $pageUid);
$viewFactoryData = new ViewFactoryData(
partialRootPaths: $partialRootPaths,
layoutRootPaths: $layoutRootPaths,
templatePathAndFilename: $contentBlockPrivatePath . '/' . ContentBlockPathUtility::getBackendPreviewFileName(),
request: $request
);
return $this->viewFactory->create($viewFactoryData);
}

/**
Expand All @@ -100,7 +105,7 @@ protected function getContentBlocksPartialRootPaths(string $contentBlockPrivateP
'EXT:backend/Resources/Private/Partials/',
'EXT:content_blocks/Resources/Private/Partials/',
...$contentBlockPartialRootPaths,
$contentBlockPrivatePath . '/Partials/',
$contentBlockPrivatePath . '/partials/',
];
return $partialRootPaths;
}
Expand All @@ -111,7 +116,7 @@ protected function getContentBlocksPartialRootPaths(string $contentBlockPrivateP
protected function getContentBlocksLayoutRootPaths(string $contentBlockPrivatePath, int $pageUid): array
{
$layoutRootPaths = $this->rootPathsSettings->getContentBlocksLayoutRootPaths($pageUid);
$layoutRootPaths[] = $contentBlockPrivatePath . '/Layouts/';
$layoutRootPaths[] = $contentBlockPrivatePath . '/layouts/';
return $layoutRootPaths;
}
}
Loading

0 comments on commit d96cbc5

Please sign in to comment.