Advertisement
Guest User

Translatable Extbase domain model

a guest
Oct 16th, 2014
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.62 KB | None | 0 0
  1. <?php
  2. namespace Vendor\MyExtension\Domain\Model;
  3.  
  4. /**
  5.  * Add this to your TypoScript setup:
  6.  *
  7.  * config.tx_extbase.persistence.classes {
  8.  *   Vendor\MyExtension\Domain\Model\Foo.mapping {
  9.  *     columns {
  10.  *       l10n_parent.mapOnProperty = translationParent
  11.  *     }
  12.  *   }
  13.  * }
  14.  *
  15.  * Usage:
  16.  *
  17.  * $fooTranslation = $objectManager->get($targetType);
  18.  * $fooTranslation->_setProperty('_languageUid', $languageUid);
  19.  * $fooTranslation->setTranslationParent($foo);
  20.  * // This allows for immediate access to translation during this request
  21.  * // and easy persistence simply by persisting the original object
  22.  * $foo->addTranslation($fooTranslation);
  23.  * // Set translated property values ...
  24.  * $fooTranslation->setBar('My translation');
  25.  * // Add/update the original object
  26.  * $fooRepository->update($foo);
  27.  */
  28. class Foo extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
  29.  
  30.   /**
  31.    * @var \Vendor\MyExtension\Domain\Model\Foo $translationParent
  32.    */
  33.   protected $translationParent;
  34.  
  35.   /**
  36.    * @return \Vendor\MyExtension\Domain\Model\Foo
  37.    */
  38.   public function getTranslationParent() {
  39.     return $this->translationParent;
  40.   }
  41.  
  42.   /**
  43.    * @param \Vendor\MyExtension\Domain\Model\Foo $translationParent
  44.    * @return void
  45.    */
  46.   public function setTranslationParent(\Vendor\MyExtension\Domain\Model\Foo $translationParent) {
  47.     $this->translationParent = $translationParent;
  48.   }
  49.  
  50.   /**
  51.    * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\MyExtension\Domain\Model\Foo>
  52.    */
  53.   protected $translations;
  54.  
  55.   /**
  56.    * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
  57.    */
  58.   public function getTranslations() {
  59.     return $this->translations;
  60.   }
  61.  
  62.   /**
  63.    * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $translations
  64.    * @return void
  65.    */
  66.   public function setTranslations(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $translations) {
  67.     $this->translations = $translations;
  68.   }
  69.  
  70.   /**
  71.    * @param \Vendor\MyExtension\Domain\Model\Foo $translationLocation
  72.    * @return void
  73.    */
  74.   public function addTranslation(\Vendor\MyExtension\Domain\Model\Foo $translationLocation) {
  75.     $this->translations->attach($translationLocation);
  76.   }
  77.  
  78.   /**
  79.    * @param \Vendor\MyExtension\Domain\Model\Foo $translationLocation
  80.    * @return void
  81.    */
  82.   public function removeTranslation(\Vendor\MyExtension\Domain\Model\Foo $translationLocation) {
  83.     $this->translations->detach($translationLocation);
  84.   }
  85.  
  86.   /**
  87.    * Sets up this object
  88.    */
  89.   public function __construct() {
  90.  
  91.     $this->translations = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
  92.   }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement