Initial Commit
This commit is contained in:
1 parent
4f495177e4
commit
b6d2142214
166 files changed
+13952
-178
No files matched your search
+122
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\View;
|
||||
|
||||
use TYPO3\CMS\Backend\View\BackendLayout\BackendLayout;
|
||||
use TYPO3\CMS\Backend\View\BackendLayout\BackendLayoutCollection;
|
||||
use TYPO3\CMS\Backend\View\BackendLayout\DataProviderContext;
|
||||
use TYPO3\CMS\Backend\View\BackendLayout\DataProviderInterface;
|
||||
|
||||
/**
|
||||
* Provides one Backend Layout per VITEC frontend layout (pages.layout 0..20).
|
||||
*
|
||||
* Backend layout identifiers are the plain layout values: '0', '1', ... '20'.
|
||||
* Combined with the provider id 'vitec' (registered in ext_localconf.php) this
|
||||
* yields the standard combined identifier scheme vitec__<value>.
|
||||
*
|
||||
* The layout's title is shown above the page module and tells the editor
|
||||
* which frontend layout is currently active.
|
||||
*/
|
||||
final class BackendLayoutDataProvider implements DataProviderInterface
|
||||
{
|
||||
/** colPos values across all VITEC backend layouts.
|
||||
* Must NOT collide with container child colPos (>= 211). */
|
||||
private const COL_POS = [
|
||||
'main' => 0,
|
||||
'hero' => 1,
|
||||
'sidebar' => 2,
|
||||
'preFooter' => 3,
|
||||
];
|
||||
|
||||
/** Per-frontend-layout: title + ordered list of zones. */
|
||||
public const LAYOUT_MAP = [
|
||||
0 => ['title' => 'Default', 'zones' => ['main']],
|
||||
1 => ['title' => 'Index Page', 'zones' => ['hero', 'main', 'preFooter']],
|
||||
2 => ['title' => 'Markets Overview', 'zones' => ['hero', 'main']],
|
||||
3 => ['title' => 'Market Detail', 'zones' => ['hero', 'main', 'sidebar']],
|
||||
4 => ['title' => 'Solutions Overview', 'zones' => ['hero', 'main']],
|
||||
5 => ['title' => 'Solution Detail', 'zones' => ['hero', 'main', 'sidebar']],
|
||||
6 => ['title' => 'Use Cases Overview', 'zones' => ['hero', 'main']],
|
||||
7 => ['title' => 'Use Case Detail', 'zones' => ['hero', 'main', 'sidebar']],
|
||||
8 => ['title' => 'Products Overview', 'zones' => ['hero', 'main']],
|
||||
9 => ['title' => 'Product Main Category', 'zones' => ['hero', 'main', 'preFooter']],
|
||||
10 => ['title' => 'Product Detail', 'zones' => ['hero', 'main', 'sidebar']],
|
||||
11 => ['title' => 'Support Overview', 'zones' => ['hero', 'main']],
|
||||
12 => ['title' => 'News Overview', 'zones' => ['hero', 'main']],
|
||||
13 => ['title' => 'News Detail V1', 'zones' => ['hero', 'main', 'sidebar']],
|
||||
14 => ['title' => 'News Detail V2', 'zones' => ['hero', 'main']],
|
||||
15 => ['title' => 'News Detail V3', 'zones' => ['hero', 'main', 'sidebar', 'preFooter']],
|
||||
16 => ['title' => 'Content Page V1', 'zones' => ['hero', 'main']],
|
||||
17 => ['title' => 'Content Page V2', 'zones' => ['hero', 'main', 'sidebar']],
|
||||
18 => ['title' => 'Content Page V3', 'zones' => ['hero', 'main', 'sidebar', 'preFooter']],
|
||||
19 => ['title' => 'Events Overview', 'zones' => ['hero', 'main']],
|
||||
20 => ['title' => 'Contact Page', 'zones' => ['hero', 'main', 'sidebar']],
|
||||
];
|
||||
|
||||
/** Display name for each zone. Shown as column header in the BE page module. */
|
||||
private const ZONE_NAMES = [
|
||||
'main' => 'Main Content',
|
||||
'hero' => 'Hero',
|
||||
'sidebar' => 'Sidebar',
|
||||
'preFooter' => 'Pre-Footer',
|
||||
];
|
||||
|
||||
public function addBackendLayouts(DataProviderContext $dataProviderContext, BackendLayoutCollection $backendLayoutCollection)
|
||||
{
|
||||
foreach (self::LAYOUT_MAP as $value => $info) {
|
||||
$backendLayoutCollection->add($this->buildBackendLayout((int)$value, $info['title'], $info['zones']));
|
||||
}
|
||||
}
|
||||
|
||||
public function getBackendLayout($identifier, $pageId)
|
||||
{
|
||||
$value = (int)$identifier;
|
||||
if (!isset(self::LAYOUT_MAP[$value])) {
|
||||
return null;
|
||||
}
|
||||
$info = self::LAYOUT_MAP[$value];
|
||||
return $this->buildBackendLayout($value, $info['title'], $info['zones']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $zones
|
||||
*/
|
||||
private function buildBackendLayout(int $value, string $title, array $zones): BackendLayout
|
||||
{
|
||||
$rowsTs = '';
|
||||
$rowNum = 1;
|
||||
foreach ($zones as $zoneKey) {
|
||||
$name = self::ZONE_NAMES[$zoneKey];
|
||||
$colPos = self::COL_POS[$zoneKey];
|
||||
$rowsTs .= <<<TS
|
||||
{$rowNum} {
|
||||
columns {
|
||||
1 {
|
||||
name = {$name}
|
||||
colPos = {$colPos}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TS;
|
||||
$rowNum++;
|
||||
}
|
||||
$rowCount = count($zones);
|
||||
$configuration = <<<TS
|
||||
backend_layout {
|
||||
colCount = 1
|
||||
rowCount = {$rowCount}
|
||||
rows {
|
||||
{$rowsTs} }
|
||||
}
|
||||
TS;
|
||||
|
||||
// Identifier is plain numeric; combined form becomes "vitec__<value>"
|
||||
return new BackendLayout(
|
||||
(string)$value,
|
||||
'VITEC Layout: ' . $title,
|
||||
$configuration
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\View;
|
||||
|
||||
use TYPO3\CMS\Extbase\Mvc\View\AbstractView;
|
||||
|
||||
/**
|
||||
* JSON View for Headless API
|
||||
*/
|
||||
class ProductListJsonView extends AbstractView
|
||||
{
|
||||
public function render(): string
|
||||
{
|
||||
$products = $this->variables['products'] ?? [];
|
||||
$productsData = [];
|
||||
|
||||
foreach ($products as $product) {
|
||||
$categories = [];
|
||||
if ($product->getCategories()) {
|
||||
foreach ($product->getCategories() as $category) {
|
||||
$categories[] = [
|
||||
'uid' => $category->getUid(),
|
||||
'title' => $category->getTitle(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$image = null;
|
||||
if ($product->getProductimage() && $product->getProductimage()->count() > 0) {
|
||||
$imageObject = $product->getProductimage()->current();
|
||||
$image = [
|
||||
'uid' => $imageObject->getUid(),
|
||||
'url' => $imageObject->getOriginalResource()->getPublicUrl(),
|
||||
'title' => $imageObject->getTitle(),
|
||||
'alternative' => $imageObject->getAlternative(),
|
||||
'description' => $imageObject->getDescription(),
|
||||
];
|
||||
}
|
||||
|
||||
$productsData[] = [
|
||||
'uid' => $product->getUid(),
|
||||
'title' => $product->getTitle(),
|
||||
'subtitle' => $product->getSubtitle(),
|
||||
'teaser' => $product->getTeaser(),
|
||||
'description' => $product->getDescription(),
|
||||
'slug' => $product->getSlug(),
|
||||
'categories' => $categories,
|
||||
'image' => $image,
|
||||
];
|
||||
}
|
||||
|
||||
return json_encode([
|
||||
'products' => $productsData,
|
||||
], JSON_THROW_ON_ERROR);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\View;
|
||||
|
||||
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
||||
use TYPO3\CMS\Backend\View\BackendLayoutView;
|
||||
|
||||
/**
|
||||
* Overrides BackendLayoutView so the page module always reflects pages.layout
|
||||
* without the editor having to set backend_layout manually.
|
||||
*/
|
||||
final class VitecBackendLayoutView extends BackendLayoutView
|
||||
{
|
||||
public function getSelectedCombinedIdentifier(int $pageId): string|false
|
||||
{
|
||||
if ($pageId <= 0) {
|
||||
return parent::getSelectedCombinedIdentifier($pageId);
|
||||
}
|
||||
|
||||
$page = BackendUtility::getRecord('pages', $pageId, 'layout');
|
||||
if (!is_array($page) || !isset($page['layout'])) {
|
||||
return parent::getSelectedCombinedIdentifier($pageId);
|
||||
}
|
||||
|
||||
// Combined identifier format: "<dataProvider>__<layoutId>"
|
||||
return 'vitec__' . (int)$page['layout'];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user