1616use Doctrine \Common \Persistence \Event \LifecycleEventArgs ;
1717use Doctrine \Common \Persistence \Event \LoadClassMetadataEventArgs ;
1818use Doctrine \ODM \PHPCR \Mapping \ClassMetadata ;
19- use Symfony \Cmf \Bundle \CoreBundle \Translatable \TranslatableInterface ;
2019
2120/**
22- * Metadata listener for when translations are disabled in PHPCR-ODM to remove
23- * mapping information that makes fields being translated.
21+ * Metadata listener for when the translations is globally defined
2422 *
25- * @author David Buchmann <mail@davidbu.ch >
23+ * @author Lukas Kahwe Smith <smith@pooteeweet.org >
2624 */
2725class TranslatableMetadataListener implements EventSubscriber
2826{
27+ /**
28+ * @var string
29+ */
30+ private $ translationStrategy ;
31+
32+ /**
33+ * @param string $translationStrategy
34+ */
35+ public function __construct ($ translationStrategy )
36+ {
37+ $ this ->translationStrategy = $ translationStrategy ;
38+ }
39+
2940 /**
3041 * @return array
3142 */
3243 public function getSubscribedEvents ()
3344 {
3445 return array (
3546 'loadClassMetadata ' ,
36- 'postLoad ' ,
3747 );
3848 }
3949
4050 /**
41- * Handle the load class metadata event: remove translated attribute from
42- * fields and remove the locale mapping if present.
51+ * Handle the load class metadata event: set the translation strategy
4352 *
4453 * @param LoadClassMetadataEventArgs $eventArgs
4554 */
@@ -49,28 +58,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
4958 $ meta = $ eventArgs ->getClassMetadata ();
5059
5160 if ($ meta ->getReflectionClass ()->implementsInterface ('Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface ' )) {
52- foreach ($ meta ->translatableFields as $ field ) {
53- unset($ meta ->mappings [$ field ]['translated ' ]);
54- }
55- $ meta ->translatableFields = array ();
56- if (null !== $ meta ->localeMapping ) {
57- unset($ meta ->mappings [$ meta ->localeMapping ]);
58- $ meta ->localeMapping = null ;
59- }
60- }
61- }
62-
63- /**
64- * We set the locale field to false so that other code can use the
65- * information that translations are deactivated.
66- *
67- * @param LifecycleEventArgs $eventArgs
68- */
69- public function postLoad (LifecycleEventArgs $ eventArgs )
70- {
71- $ object = $ eventArgs ->getObject ();
72- if ($ object instanceof TranslatableInterface) {
73- $ object ->setLocale (false );
61+ $ meta ->setTranslator ($ this ->translationStrategy );
7462 }
7563 }
7664}
0 commit comments