-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from tritum/version/4.x.x
Version/4.x.x TYPO3 v12 compatibility
- Loading branch information
Showing
14 changed files
with
447 additions
and
173 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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
/* | ||
* This file is part of the TYPO3 CMS extension "repeatable_form_elements". | ||
* | ||
* Copyright (C) 2018 Ralf Zimmermann TRITUM GmbH <ralf.zimmermann@tritum.de> | ||
* Copyright (C) 2018 Ralf Zimmermann dreistrom.land AG <r.zimmermann@dreistrom.land> | ||
* Copyright (C) 2021 Elias Häußler <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
|
@@ -27,14 +27,16 @@ | |
use TRITUM\RepeatableFormElements\Hooks\FormHooks; | ||
use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider; | ||
use TYPO3\CMS\Core\Imaging\IconRegistry; | ||
use TYPO3\CMS\Core\Information\Typo3Version; | ||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* Extension | ||
* | ||
* @author Ralf Zimmermann TRITUM GmbH <ralf.zimmermann@tritum.de> | ||
* @author Ralf Zimmermann | dreistrom.land AG <r.zimmermann@dreistrom.land> | ||
* @author Elias Häußler <[email protected]> | ||
* @author Christian Seyfferth | dreistrom.land AG <[email protected]> | ||
* @license GPL-2.0-or-later | ||
*/ | ||
final class Extension | ||
|
@@ -43,6 +45,7 @@ final class Extension | |
|
||
public static function addTypoScriptSetup(): void | ||
{ | ||
// @todo: maybe move this to 'EXT:repeatable_form_elements/ext_typoscript_setup.typoscript' | ||
ExtensionManagementUtility::addTypoScriptSetup(trim(' | ||
module.tx_form { | ||
settings { | ||
|
@@ -57,6 +60,8 @@ public static function addTypoScriptSetup(): void | |
|
||
public static function registerIcons(): void | ||
{ | ||
if ('12.4' <= self::getTypo3Version()) return; | ||
|
||
$iconRegistry = GeneralUtility::makeInstance(IconRegistry::class); | ||
$iconRegistry->registerIcon( | ||
't3-form-icon-repeatable-container', | ||
|
@@ -70,4 +75,9 @@ public static function registerHooks(): void | |
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['afterInitializeCurrentPage'][1511196413] = FormHooks::class; | ||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['beforeRendering'][1511196413] = FormHooks::class; | ||
} | ||
|
||
private static function getTypo3Version() : string | ||
{ | ||
return (new Typo3Version())->getVersion(); | ||
} | ||
} |
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,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TRITUM\RepeatableFormElements\Event; | ||
|
||
/** | ||
* This file is part of the "repeatable_form_elements" Extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
use TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface; | ||
|
||
/** | ||
* Use this event to manipulate variantOptions on copying form elements | ||
*/ | ||
class CopyVariantEvent | ||
{ | ||
private array $options; | ||
private FormElementInterface $originalFormElement; | ||
private FormElementInterface $newFormElement; | ||
private string $newIdentifier; | ||
private bool $variantEnabled = true; | ||
|
||
public function __construct( | ||
array $options, | ||
FormElementInterface $originalFormElement, | ||
FormElementInterface $newFormElement, | ||
string $newIdentifier | ||
) | ||
{ | ||
$this->options = $options; | ||
$this->originalFormElement = $originalFormElement; | ||
$this->newFormElement = $newFormElement; | ||
$this->newIdentifier = $newIdentifier; | ||
} | ||
|
||
public function getOptions(): array | ||
{ | ||
return $this->options; | ||
} | ||
|
||
public function setOptions(array $options): void | ||
{ | ||
$this->options = $options; | ||
} | ||
|
||
public function getOriginalFormElement(): FormElementInterface | ||
{ | ||
return $this->originalFormElement; | ||
} | ||
|
||
public function getNewFormElement(): FormElementInterface | ||
{ | ||
return $this->newFormElement; | ||
} | ||
|
||
public function getNewIdentifier(): string | ||
{ | ||
return $this->newIdentifier; | ||
} | ||
|
||
public function isVariantEnabled(): bool | ||
{ | ||
return $this->variantEnabled; | ||
} | ||
|
||
public function setVariantEnabled(bool $variantEnabled): void | ||
{ | ||
$this->variantEnabled = $variantEnabled; | ||
} | ||
|
||
|
||
} |
50 changes: 50 additions & 0 deletions
50
Classes/EventListener/AdaptVariantConditionEventListener.php
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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TRITUM\RepeatableFormElements\EventListener; | ||
|
||
/** | ||
* This file is part of the "repeatable_form_elements" Extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
use TRITUM\RepeatableFormElements\Event\CopyVariantEvent; | ||
|
||
|
||
/** | ||
* Replace original identifiers inside variant condition with identifiers of new element | ||
* | ||
* @param CopyVariantEvent $event | ||
* @return void | ||
*/ | ||
final class AdaptVariantConditionEventListener | ||
{ | ||
public function __invoke(CopyVariantEvent $event): void | ||
{ | ||
$options = $event->getOptions(); | ||
$originalIdentifier = $event->getOriginalFormElement()->getIdentifier(); | ||
|
||
// get path strings for identifiers for replacement in condition | ||
// e.g. for `traverse(formValues, 'repeatablecontainer-1.0.checkbox-1')` | ||
$originalIdentifierAsPath = str_replace('.', '/', $originalIdentifier); | ||
$newIdentifierAsPath = str_replace('.', '/', $event->getNewIdentifier()); | ||
|
||
// adapt original condition to match identifier of the copied form element | ||
$options['condition'] = str_replace( | ||
[ | ||
$originalIdentifier, | ||
$originalIdentifierAsPath | ||
], | ||
[ | ||
$event->getNewIdentifier(), | ||
$newIdentifierAsPath | ||
], | ||
$options['condition'] | ||
); | ||
|
||
$event->setOptions($options); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace TRITUM\RepeatableFormElements\FormElements; | ||
|
||
/** | ||
|
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.