protected function setUp() { parent::setUp(); $evm = new EventManager(); $translationListener = new TranslationListener(); $translationListener->setTranslatableLocale('en_us'); $evm->addEventSubscriber($translationListener); $evm->addEventSubscriber(new TimestampableListener()); $this->getMockSqliteEntityManager($evm); }
/** * Makes additional translation of $entity $field into $locale * using $value * * @param object $entity * @param string $field * @param string $locale * @param mixed $value * @return TranslationRepository */ public function translate($entity, $field, $locale, $value) { $meta = $this->_em->getClassMetadata(get_class($entity)); $config = $this->getTranslationListener()->getConfiguration($this->_em, $meta->name); if (!isset($config['fields']) || !in_array($field, $config['fields'])) { throw new \Gedmo\Exception\InvalidArgumentException("Entity: {$meta->name} does not translate - {$field}"); } $oid = spl_object_hash($entity); $this->listener->addTranslation($oid, $field, $locale, $value); return $this; }
public function testTranslatableMetadata() { $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\Translatable'); $config = $this->translatable->getConfiguration($this->em, $meta->name); $this->assertArrayHasKey('translationClass', $config); $this->assertEquals('Gedmo\\Translatable\\Entity\\Translation', $config['translationClass']); $this->assertArrayHasKey('locale', $config); $this->assertEquals('locale', $config['locale']); $this->assertArrayHasKey('fields', $config); $this->assertEquals(2, count($config['fields'])); $this->assertTrue(in_array('title', $config['fields'])); $this->assertTrue(in_array('content', $config['fields'])); }
public function getTranslationClass(TranslatableAdapter $ea, $class) { $class = parent::getTranslationClass($ea, $class); if ($class === 'Gedmo\\Translatable\\Entity\\Translation') { return 'Stof\\DoctrineExtensionsBundle\\Entity\\Translation'; } elseif ($class === 'Gedmo\\Translatable\\Document\\Translation') { return 'Stof\\DoctrineExtensionsBundle\\Document\\Translation'; } return $class; }
/** * Search for translated components in the select clause * * @param array $queryComponents * @return void */ private function extractTranslatedComponents(array $queryComponents) { $em = $this->getEntityManager(); foreach ($queryComponents as $alias => $comp) { if (!isset($comp['metadata'])) { continue; } $meta = $comp['metadata']; $config = $this->listener->getConfiguration($em, $meta->name); if ($config && isset($config['fields'])) { $this->translatedComponents[$alias] = $comp; } } }