Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Vendor\MyExtension\Domain\Model;
- /**
- * Add this to your TypoScript setup:
- *
- * config.tx_extbase.persistence.classes {
- * Vendor\MyExtension\Domain\Model\Foo.mapping {
- * columns {
- * l10n_parent.mapOnProperty = translationParent
- * }
- * }
- * }
- *
- * Usage:
- *
- * $fooTranslation = $objectManager->get($targetType);
- * $fooTranslation->_setProperty('_languageUid', $languageUid);
- * $fooTranslation->setTranslationParent($foo);
- * // This allows for immediate access to translation during this request
- * // and easy persistence simply by persisting the original object
- * $foo->addTranslation($fooTranslation);
- * // Set translated property values ...
- * $fooTranslation->setBar('My translation');
- * // Add/update the original object
- * $fooRepository->update($foo);
- */
- class Foo extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
- /**
- * @var \Vendor\MyExtension\Domain\Model\Foo $translationParent
- */
- protected $translationParent;
- /**
- * @return \Vendor\MyExtension\Domain\Model\Foo
- */
- public function getTranslationParent() {
- return $this->translationParent;
- }
- /**
- * @param \Vendor\MyExtension\Domain\Model\Foo $translationParent
- * @return void
- */
- public function setTranslationParent(\Vendor\MyExtension\Domain\Model\Foo $translationParent) {
- $this->translationParent = $translationParent;
- }
- /**
- * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\MyExtension\Domain\Model\Foo>
- */
- protected $translations;
- /**
- * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
- */
- public function getTranslations() {
- return $this->translations;
- }
- /**
- * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $translations
- * @return void
- */
- public function setTranslations(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $translations) {
- $this->translations = $translations;
- }
- /**
- * @param \Vendor\MyExtension\Domain\Model\Foo $translationLocation
- * @return void
- */
- public function addTranslation(\Vendor\MyExtension\Domain\Model\Foo $translationLocation) {
- $this->translations->attach($translationLocation);
- }
- /**
- * @param \Vendor\MyExtension\Domain\Model\Foo $translationLocation
- * @return void
- */
- public function removeTranslation(\Vendor\MyExtension\Domain\Model\Foo $translationLocation) {
- $this->translations->detach($translationLocation);
- }
- /**
- * Sets up this object
- */
- public function __construct() {
- $this->translations = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement