Skip to content

Commit

Permalink
[BUGFIX] Add legacy method for registering data transformers (#2192)
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder authored Oct 28, 2024
1 parent 83fe4e3 commit a167840
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Classes/Form/Transformation/DataTransformerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

use Symfony\Component\DependencyInjection\ServiceLocator;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class DataTransformerRegistry
{
Expand All @@ -18,6 +19,8 @@ class DataTransformerRegistry
*/
private array $transformers = [];

private static array $legacy = [];

public function __construct(ServiceLocator $locator)
{
/** @var DataTransformerInterface[] $transformers */
Expand All @@ -31,6 +34,11 @@ function (DataTransformerInterface $a, DataTransformerInterface $b) {
);
}

public static function registerTransformerOnLegacyPhpVersion(string $transformerClassName): void
{
self::$legacy[] = $transformerClassName;
}

public function resolveDataTransformerByType(string $type): DataTransformerInterface
{
foreach ($this->transformers as $transformer) {
Expand All @@ -39,6 +47,15 @@ public function resolveDataTransformerByType(string $type): DataTransformerInter
}
}

/** @var class-string $legacyClassName */
foreach (self::$legacy as $legacyClassName) {
/** @var DataTransformerInterface $transformer */
$transformer = GeneralUtility::makeInstance($legacyClassName);
if ($transformer->canTransformToType($type)) {
return $transformer;
}
}

throw new \InvalidArgumentException(
'Flux could not resolve a data transformer for type "' . $type . '"',
1720346755
Expand Down
4 changes: 4 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ services:
arguments:
$locator: !tagged_locator { tag: 'flux.datatransformer', index_by: 'identifier' }

# This entry only exists for PHP <8 to be able to load FileTransformer. Don't rely on being able to construct this!
FluidTYPO3\Flux\Form\Transformation\Transformer\FileTransformer:
public: true

FluidTYPO3\Flux\Integration\HookSubscribers\ColumnPositionItems:
public: true
FluidTYPO3\Flux\Backend\BackendLayoutDataProvider:
Expand Down
9 changes: 9 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@

$GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'] .= ($GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'] == '' ? '' : ',') .
'tx_fed_page_controller_action,tx_fed_page_controller_action_sub,tx_fed_page_flexform,tx_fed_page_flexform_sub,';
if (version_compare((string) PHP_MAJOR_VERSION, '8.0', '<')) {
\FluidTYPO3\Flux\Form\Transformation\DataTransformerRegistry::registerTransformerOnLegacyPhpVersion(\FluidTYPO3\Flux\Form\Transformation\Transformer\ArrayTransformer::class);
\FluidTYPO3\Flux\Form\Transformation\DataTransformerRegistry::registerTransformerOnLegacyPhpVersion(\FluidTYPO3\Flux\Form\Transformation\Transformer\BooleanTransformer::class);
\FluidTYPO3\Flux\Form\Transformation\DataTransformerRegistry::registerTransformerOnLegacyPhpVersion(\FluidTYPO3\Flux\Form\Transformation\Transformer\FileTransformer::class);
\FluidTYPO3\Flux\Form\Transformation\DataTransformerRegistry::registerTransformerOnLegacyPhpVersion(\FluidTYPO3\Flux\Form\Transformation\Transformer\FloatTransformer::class);
\FluidTYPO3\Flux\Form\Transformation\DataTransformerRegistry::registerTransformerOnLegacyPhpVersion(\FluidTYPO3\Flux\Form\Transformation\Transformer\FunctionCallTransformer::class);
\FluidTYPO3\Flux\Form\Transformation\DataTransformerRegistry::registerTransformerOnLegacyPhpVersion(\FluidTYPO3\Flux\Form\Transformation\Transformer\IntegerTransformer::class);
\FluidTYPO3\Flux\Form\Transformation\DataTransformerRegistry::registerTransformerOnLegacyPhpVersion(\FluidTYPO3\Flux\Form\Transformation\Transformer\ObjectTransformer::class);
}
}

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update'][\FluidTYPO3\Flux\Updates\MigrateColPosWizard::class]
Expand Down

0 comments on commit a167840

Please sign in to comment.