Skip to content

Commit

Permalink
Merge branch 'feature/typo3-update/v12'
Browse files Browse the repository at this point in the history
  • Loading branch information
Digi92 committed Aug 29, 2024
2 parents 5b98d53 + de9c4ad commit 345cab4
Show file tree
Hide file tree
Showing 55 changed files with 681 additions and 725 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
.DS_Store

#IDE
.idea
.idea

#Build
vendor
Original file line number Diff line number Diff line change
@@ -1,54 +1,26 @@
<?php

namespace Denkwerk\DwContentElements\Hooks;

/***************************************************************
* Copyright notice
*
* (c) 2015 Sascha Zander <[email protected]>
* (c) 2016 Johann Derdak <[email protected]>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
declare(strict_types=1);

namespace Denkwerk\DwContentElements\Backend\EventListener;

use Denkwerk\DwContentElements\Service\IniProviderService;
use Denkwerk\DwContentElements\Service\IniService;
use Denkwerk\DwContentElements\Service\IrreService;
use Denkwerk\DwContentElements\Service\UrlService;
use TYPO3\CMS\Backend\Form\Exception;
use TYPO3\CMS\Backend\Form\Exception\AccessDeniedTableModifyException;
use TYPO3\CMS\Backend\Form\FormDataCompiler;
use TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
use TYPO3\CMS\Backend\View\Event\PageContentPreviewRenderingEvent;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

/**
* Class PageLayoutViewDrawItemHook
* @package Denkwerk\DwContentElements\Hooks
*/
class PageLayoutViewDrawItemHook implements PageLayoutViewDrawItemHookInterface
class PreviewEventListener
{

/**
* @var IniService $iniService
*/
Expand All @@ -67,25 +39,11 @@ public function __construct()
$this->iniService = GeneralUtility::makeInstance(IniService::class);
$this->iniProviderService = GeneralUtility::makeInstance(IniProviderService::class);
}

/**
* Preprocessed the preview rendering of a content element.
*
* @param PageLayoutView $parentObject : Calling parent object
* @param boolean $drawItem : Whether to draw the item using the default functionalities
* @param string $headerContent : Header content
* @param string $itemContent : Item content
* @param array $row : Record row of tt_content
* @return void
* @throws \TYPO3\CMS\Backend\Form\Exception
*/
public function preProcess(
PageLayoutView &$parentObject,
&$drawItem,
&$headerContent,
&$itemContent,
array &$row
) {
public function __invoke(PageContentPreviewRenderingEvent $event): void
{
if ($event->getTable() !== 'tt_content') {
return;
}

/// Load all provider configurations as array
$providers = $this->iniProviderService->loadProvider();
Expand All @@ -102,6 +60,8 @@ public function preProcess(
}
}

$row = $event->getRecord();

// If it is an dwc content element
if (isset($row['CType']) &&
!is_array($row['CType']) &&
Expand Down Expand Up @@ -136,7 +96,8 @@ public function preProcess(
(isset($field['label']) &&
empty($field['label']) === false ?
$field['label'] :
$parentObject->itemLabels[$field['name']]
//todo: make sure field exists
$event->getPageLayoutContext()->getItemLabels()[$field['name']]
)
);

Expand All @@ -147,6 +108,8 @@ public function preProcess(
}
}
$itemContent .= '</div>';

$event->setPreviewContent($itemContent);
}
}

Expand All @@ -158,7 +121,7 @@ public function preProcess(
* @param string $itemLabels
* @param string $fieldTable
* @return string
* @throws \TYPO3\CMS\Backend\Form\Exception
* @throws Exception
*/
public function renderFieldPreview($fieldName, $row, $itemLabels = '', $fieldTable = 'tt_content')
{
Expand Down Expand Up @@ -304,8 +267,8 @@ public function renderFieldPreview($fieldName, $row, $itemLabels = '', $fieldTab
case "selectCheckBox":
$value = explode(',', $fieldValue);
foreach ($items as $item) {
$filedContent .= $item[0] . ' ' .
(in_array($item[1], $value) ? '&#10004;' : '&#10008;') .
$filedContent .= $item['label'] . ' ' .
(in_array($item['value'], $value) ? '&#10004;' : '&#10008;') .
'<br />';
}
break;
Expand All @@ -315,16 +278,17 @@ public function renderFieldPreview($fieldName, $row, $itemLabels = '', $fieldTab
$value = explode(',', $fieldValue);
$selectedContent = array();
foreach ($items as $item) {
if (in_array($item[1], $value)) {
$selectedContent[] = $item[0];
if (in_array($item['value'], $value)) {
$selectedContent[] = $item['label'];
}
}
$filedContent .= implode("<br />", $selectedContent);
break;
default:
foreach ($items as $item) {
if ($item[1] == $fieldValue) {
$filedContent .= $item[0];
if ($item['value'] == $fieldValue) {

$filedContent .= $item['label'];
}
}
}
Expand Down Expand Up @@ -359,16 +323,12 @@ public function renderFieldPreview($fieldName, $row, $itemLabels = '', $fieldTab
$filedContent .= ($filePreview != '' ? $filePreview : 'No File');
} else {
if (isset($fieldConfig['foreign_table'])) {
/** @var ContentObjectRenderer $contentObj */
$contentObj = GeneralUtility::makeInstance(
ContentObjectRenderer::class
);
$contentObj->data = $row;

$count = 0;
$filedContent .= '<p style="padding-right: 5px;margin:0;">';

foreach (IrreService::getRelations(
$contentObj,
$row,
$fieldConfig['foreign_table']
) as $item) {
$irreItemLabel = $item[$GLOBALS['TCA'][$fieldConfig['foreign_table']]['ctrl']['label']];
Expand Down Expand Up @@ -397,7 +357,7 @@ public function renderFieldPreview($fieldName, $row, $itemLabels = '', $fieldTab
$filedContent .= '</div>';
}

return $filedContent;
return $filedContent ;
}

/**
Expand Down Expand Up @@ -496,8 +456,9 @@ protected function explodeSingleFieldShowItemConfiguration($field)

return array(
'fieldName' => $fieldArray[0],
'fieldLabel' => isset($fieldArray[1]) ?? null,
'paletteName' => isset($fieldArray[2]) ?? null,
'fieldLabel' => (isset($fieldArray[1]) && trim($fieldArray[1]) !== '' ? $fieldArray[1] : null),
'paletteName' => (isset($fieldArray[2]) && trim($fieldArray[2]) !== '' ? $fieldArray[2] : null)
);
}
}

}
67 changes: 49 additions & 18 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,43 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException;
use Denkwerk\DwContentElements\Service\FileService;
use Denkwerk\DwContentElements\Service\IniProviderService;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;

/**
* Class BackendController
* @package Denkwerk\DwContentElements\Controller
*/
class BackendController extends ActionController
{

/**
* @param ModuleTemplateFactory $moduleTemplateFactory
*/
public function __construct(
protected readonly ModuleTemplateFactory $moduleTemplateFactory
) {
}

/**
* First load action, will display information about the creation of a content element
* or send the user to the right step of create the source extension
*
* @return void
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
*/
public function indexAction()
public function indexAction(): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setTitle('Dw Content Elements: Overview');

/** @var IniProviderService $iniProviderService */
$iniProviderService = GeneralUtility::makeInstance(IniProviderService::class);

Expand All @@ -61,61 +75,78 @@ public function indexAction()
) {
// Check if source extension exists
if (!is_dir(Environment::getPublicPath() . '/typo3conf/ext/dw_content_elements_source')) {
$this->forward('createSourceExt');
return $this->redirect(
'createSourceExt',
'Backend',
'dw_content_elements'
);
} else {
$this->forward('loadSourceExt');
return $this->redirect(
'loadSourceExt',
'Backend',
'dw_content_elements'
);
}
}
return $moduleTemplate->renderResponse('Index');
}

/**
* Action for the create of the source extension
*
* @return void
*
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
*/
public function createSourceExtAction()
public function createSourceExtAction(): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setTitle('Dw Content Elements: Create source extension');

if ($this->request->hasArgument('createSourceExt')) {
/**
* @var FileService $fileService
*/
$fileService = $this->objectManager->get(
FileService::class
);
$fileService = GeneralUtility::makeInstance(FileService::class);
$fileService->setSourceExtensionDirectory(
Environment::getPublicPath() . '/typo3conf/ext/dw_content_elements_source/'
);
$success = $fileService->createSourceExt();

if ($success) {
$this->forward(
return $this->redirect(
'loadSourceExt',
'Backend',
null,
array(
'dw_content_elements',
[
'hasCreatedSourceExt' => true,
)
]
);
} else {
$this->view->assign('createFail', true);
$moduleTemplate->assign('createFail', true);
}
}

return $moduleTemplate->renderResponse('CreateSourceExt');
}

/**
* Action for the info to install the source extension at the extension manager
*
* @return void
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
* @throws NoSuchArgumentException
*/
public function loadSourceExtAction()
public function loadSourceExtAction(): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setTitle('Dw Content Elements: Load source extension');

$hasCreatedSourceExt = false;

if ($this->request->hasArgument('hasCreatedSourceExt')) {
$hasCreatedSourceExt = $this->request->getArgument('hasCreatedSourceExt');
}
$this->view->assign('hasCreatedSourceExt', $hasCreatedSourceExt);

$moduleTemplate->assign('hasCreatedSourceExt', $hasCreatedSourceExt);
return $moduleTemplate->renderResponse('LoadSourceExt');
}
}
Loading

0 comments on commit 345cab4

Please sign in to comment.