Forked from helhum/PersistentObjectConverter.php
Last active
September 19, 2025 11:24
-
-
Save kitzberger/33c3c767de87e8c8abbd1767bcc01ebd to your computer and use it in GitHub Desktop.
TYPO3 12+13: Extbase TypeConverter to fetch hidden records from persistence (Using this will *always* fetch hidden models of the specified type)
This file contains hidden or 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
<?php | |
namespace MyVendor\MyExtension\Controller; | |
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; | |
class MyModelController extends ActionController | |
{ | |
public function initializeCreateAction(): void | |
{ | |
$propertyMappingConfig = $this->arguments['myModel']->getPropertyMappingConfiguration(); | |
// Use custom HiddenMyModelConverter to handle hidden records | |
$propertyMappingConfig | |
->setTypeConverter( | |
GeneralUtility::makeInstance(HiddenMyModelConverter::class) | |
); | |
} | |
public function createAction(MyModel $myModel): ResponseInterface | |
{ | |
// Should be a hidden myModel entity | |
dd($myModel); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace MyVendor\MyExtension\Controller; | |
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; | |
class MyOtherModelController extends ActionController | |
{ | |
public function initializeCreateAction(): void | |
{ | |
$propertyMappingConfig = $this->arguments['myOtherModel']->getPropertyMappingConfiguration(); | |
// Allow all properties to be set | |
$propertyMappingConfig->allowAllProperties(); | |
// Set explicit type converter for 'date' property | |
$propertyMappingConfig->forProperty('date') | |
->setTypeConverterOption( | |
DateTimeConverter::class, | |
DateTimeConverter::CONFIGURATION_DATE_FORMAT, | |
'Y-m-d' | |
); | |
// Use custom HiddenMyModelConverter for 'myModel' property to handle hidden records | |
$propertyMappingConfig->forProperty('myModel') | |
->setTypeConverter( | |
GeneralUtility::makeInstance(HiddenMyModelConverter::class) | |
); | |
} | |
public function createAction(MyOtherModel $myOtherModel): ResponseInterface | |
{ | |
// Should be a record containing a hidden myModel property | |
dd($myOtherModel); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment