Created
April 30, 2016 11:39
-
-
Save istvankis/0010cf0e318258146d4f203007aaf1e2 to your computer and use it in GitHub Desktop.
This file contains 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
AppBundle\Entity\Lang: | |
lang_0: | |
lang: | |
en: French | |
fr: Français | |
lang_1: | |
lang: | |
en: English | |
fr: Anglais |
This file contains 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
alice.processor.translatable: | |
class: AppBundle\DataFixtures\Processor\TranslatableProcessor | |
arguments: | |
- '@doctrine.orm.entity_manager' | |
- '@gedmo.listener.translatable' | |
tags: [ { name: hautelook_alice.alice.processor } ] |
This file contains 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 AppBundle\DataFixtures\Processor; | |
use Doctrine\ORM\EntityManager; | |
use Gedmo\Tool\Wrapper\AbstractWrapper; | |
use Gedmo\Translatable\Translatable; | |
use Gedmo\Translatable\TranslatableListener; | |
use Nelmio\Alice\ProcessorInterface; | |
class TranslatableProcessor implements ProcessorInterface | |
{ | |
/** | |
* @var EntityManager | |
*/ | |
private $entityManager; | |
/** | |
* @var TranslatableListener | |
*/ | |
private $translatableListener; | |
/** | |
* @var Translatable | |
*/ | |
private $translateRepository; | |
/** | |
* TranslatableProcessor constructor. | |
* @param EntityManager $entityManager | |
* @param TranslatableListener $translatableListener | |
*/ | |
public function __construct(EntityManager $entityManager, TranslatableListener $translatableListener) | |
{ | |
$this->entityManager = $entityManager; | |
$this->translatableListener = $translatableListener; | |
$this->translateRepository = $entityManager->getRepository("Gedmo\\Translatable\\Entity\\Translation"); | |
} | |
public function postProcess($object) | |
{ | |
} | |
public function preProcess($object) | |
{ | |
$translationConfig = $this->translatableListener | |
->getConfiguration($this->entityManager, get_class($object)); | |
if ($translationConfig && isset($translationConfig['fields'])) { | |
foreach ($translationConfig['fields'] as $field) { | |
$wrapped = AbstractWrapper::wrap($object, $this->entityManager); | |
$propertyValue = $wrapped->getPropertyValue($field); | |
if (is_array($propertyValue)) { | |
$wrapped->setPropertyValue($field, $propertyValue[$translationConfig['fallback'][$field]]); | |
foreach ($propertyValue as $local => $content) { | |
$this->translateRepository->translate($object, $field, $local, $content); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Have a look on this https://gist.github.com/pitpit/ce6df260fea08e61a6e5c5e7cb668d59 for a way that does not require any code