Znalazłem w sieci przykład dokumentu zawierającego pole image, które może zmieniać się w zależności od wersji językowej. Jednak nie mam pojęcia jak tego używać tzn jak wyświetlać takie pole? Czy jest możliwy upload do tego pola po stronie sonata admin? Czy ma ktoś gotowy kod który może mi tu wkleić jak z tego korzystać w praktyce? W przykładzie jest tylko pokazane jak importować taki dokument programowo ale już o wyświetlaniu nic nie mogę znaleźć.

  1. use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
  2.  
  3. /**
  4.  * @PHPCRODM\Document(alias="translation_article", translator="attribute")
  5.  */
  6. class Article
  7. {
  8. /** @PHPCRODM\Id */
  9. public $id;
  10.  
  11. /**
  12.   * The language this document currently is in
  13.   * @PHPCRODM\Locale
  14.   */
  15. public $locale = 'en';
  16.  
  17. /**
  18.   * Untranslated property
  19.   * @PHPCRODM\Date
  20.   */
  21. public $publishDate;
  22.  
  23. /**
  24.   * Translated property
  25.   * @PHPCRODM\String(translated=true)
  26.   */
  27. public $topic;
  28.  
  29. /**
  30.   * Language specific image
  31.   * @PHPCRODM\Binary(translated=true)
  32.   */
  33. public $image;
  34. }
  35.  
  36.  
  37. $localePrefs = array(
  38. 'en' => array('en', 'fr'),
  39. 'fr' => array('fr', 'en'),
  40. );
  41.  
  42. $dm = new \Doctrine\ODM\PHPCR\DocumentManager($session, $config);
  43. $dm->setLocaleChooserStrategy(new LocaleChooser($localePrefs, 'en'));
  44.  
  45. // then to use translations:
  46.  
  47. $doc = new Article();
  48. $doc->id = '/my_test_node';
  49. $doc->publishedDate = new \DateTime();
  50. $doc->topic = 'An interesting subject';
  51. $doc->image = fopen('english.jpg');
  52.  
  53. // Persist the document in English
  54. $this->dm->persistTranslation($this->doc, 'en');
  55.  
  56. // Change the content and persist the document in French
  57. $this->doc->topic = 'Un sujet intéressant';
  58. $doc->image = fopen('english.jpg');
  59. $this->dm->persistTranslation($this->doc, 'fr');
  60.  
  61. // Flush to write the changes to the phpcr backend
  62. $this->dm->flush();
  63.  
  64. // Get the document in default language (English if you bootstrapped as in the example)
  65. $doc = $this->dm->find('Doctrine\Tests\Models\Translation\Article', '/my_test_node');
  66. echo $doc->topic;
  67.  
  68. // Get the document in French (updates the existing document)
  69. $this->dm->find('Doctrine\Tests\Models\Translation\Article', '/my_test_node', 'fr');
  70. echo $doc->topic;