-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Added PluginPreview, Converted list to CType and added migration
- Loading branch information
1 parent
a895605
commit 33a070f
Showing
14 changed files
with
282 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the package jweiland/weather2. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JWeiland\Weather2\Backend\Preview; | ||
|
||
use TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer; | ||
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem; | ||
use TYPO3\CMS\Core\Service\FlexFormService; | ||
use TYPO3\CMS\Core\View\ViewFactoryData; | ||
use TYPO3\CMS\Core\View\ViewFactoryInterface; | ||
use TYPO3\CMS\Core\View\ViewInterface; | ||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; | ||
|
||
/** | ||
* Add plugin preview for EXT:weather2 | ||
*/ | ||
class Weather2PluginPreview extends StandardContentPreviewRenderer | ||
{ | ||
private const PREVIEW_TEMPLATE = 'EXT:weather2/Resources/Private/Templates/PluginPreview/Weather2.html'; | ||
|
||
private const ALLOWED_PLUGINS = [ | ||
'weather2_currentweather', | ||
'weather2_weatheralert', | ||
]; | ||
|
||
public function __construct( | ||
protected FlexFormService $flexFormService, | ||
protected ViewFactoryInterface $viewFactory | ||
) {} | ||
|
||
public function renderPageModulePreviewContent(GridColumnItem $item): string | ||
{ | ||
$ttContentRecord = $item->getRecord(); | ||
if (!$this->isValidPlugin($ttContentRecord)) { | ||
return ''; | ||
} | ||
|
||
$view = $this->viewFactory->create(new ViewFactoryData( | ||
templatePathAndFilename: self::PREVIEW_TEMPLATE | ||
)); | ||
$view->assignMultiple($ttContentRecord); | ||
|
||
$this->addPluginName($view, $ttContentRecord); | ||
|
||
// Add data from column pi_flexform | ||
$piFlexformData = $this->getPiFlexformData($ttContentRecord); | ||
if ($piFlexformData !== []) { | ||
$view->assign('pi_flexform_transformed', $piFlexformData); | ||
} | ||
|
||
return $view->render(); | ||
} | ||
|
||
protected function isValidPlugin(array $ttContentRecord): bool | ||
{ | ||
if (!isset($ttContentRecord['CType'])) { | ||
return false; | ||
} | ||
|
||
if (!in_array($ttContentRecord['CType'], self::ALLOWED_PLUGINS, true)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
protected function addPluginName(ViewInterface $view, array $ttContentRecord): void | ||
{ | ||
$langKey = sprintf( | ||
'plugin.%s.title', | ||
str_replace('weather2_', '', $ttContentRecord['CType']) | ||
); | ||
|
||
$view->assign( | ||
'pluginName', | ||
LocalizationUtility::translate('LLL:EXT:weather2/Resources/Private/Language/locallang_db.xlf:' . $langKey) | ||
); | ||
} | ||
|
||
protected function getPiFlexformData(array $ttContentRecord): array | ||
{ | ||
$data = []; | ||
if (!empty($ttContentRecord['pi_flexform'] ?? '')) { | ||
$data = $this->flexFormService->convertFlexFormContentToArray($ttContentRecord['pi_flexform']); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the package jweiland/weather2. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace JWeiland\Weather2\Updates; | ||
|
||
use TYPO3\CMS\Install\Attribute\UpgradeWizard; | ||
use TYPO3\CMS\Install\Updates\AbstractListTypeToCTypeUpdate; | ||
|
||
/** | ||
* With TYPO3 13 all plugins have to be declared as content elements (CType) insteadof "list_type" | ||
*/ | ||
#[UpgradeWizard('weather2_migratePluginsToContentElementsUpdate')] | ||
class PluginToContentElementUpdate extends AbstractListTypeToCTypeUpdate | ||
{ | ||
protected function getListTypeToCTypeMapping(): array | ||
{ | ||
return [ | ||
'weather2_currentweather' => 'weather2_currentweather', | ||
'weather2_weatheralert' => 'weather2_weatheralert', | ||
]; | ||
} | ||
|
||
public function getTitle(): string | ||
{ | ||
return 'Migrate plugins to Content Elements'; | ||
} | ||
|
||
public function getDescription(): string | ||
{ | ||
return 'The modern way to register plugins for TYPO3 is to register them as content element types. ' . | ||
'Running this wizard will migrate all weather2 plugins to content element (CType)'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name: jweiland/weather2 | ||
label: Weather2 Extension Settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
categories: | ||
Weather2: | ||
label: 'Weather2' | ||
Weather2.templates: | ||
label: 'Templates' | ||
parent: Weather2 | ||
Weather2.pages: | ||
label: 'Pages' | ||
parent: Weather2 | ||
|
||
settings: | ||
weather2.templateRootPath: | ||
label: 'Templates' | ||
category: Weather2.templates | ||
description: 'Path to template root' | ||
type: string | ||
default: 'EXT:weather2/Resources/Private/Templates/' | ||
weather2.partialRootPath: | ||
label: 'Partials' | ||
category: Weather2.templates | ||
description: 'Path to partial root' | ||
type: string | ||
default: 'EXT:weather2/Resources/Private/Partials/' | ||
weather2.layoutRootPath: | ||
label: 'Layouts' | ||
category: Weather2.templates | ||
description: 'Path to layout root' | ||
type: string | ||
default: 'EXT:weather2/Resources/Private/Layouts/' | ||
weather2.iconsPath: | ||
label: 'Icons Path' | ||
category: Weather2.templates | ||
description: 'Path for weather icons' | ||
type: string | ||
default: 'EXT:weather2/Resources/Public/WeatherIcons/' | ||
weather2.storagePid: | ||
label: 'Default storage PID' | ||
category: Weather2.pages | ||
description: 'Folder for storing weather records and fetched data' | ||
type: int | ||
default: 0 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.