Witam

Korzystam z https://github.com/Atlantic18/DoctrineExtensions, dokładnie interesuje mnie wdrożenie do swojego projektu translatable i sluggable. Najpierw podpiąłem bez wiekszych problemów translatable, język domyślny to polski, tłumaczę na angielski i na niemiecki. Wszystko pięknie działa, dodawanie, edycja, usuwanie. Potem podpiąłem sluggable, też ładnie działa, ale jedynie z domyślnym językiem. Natomiast nie tworzy i nie zapisuje slug'ów z innych języków. Przekopałem cały internet i nie mogę znaleźć rozwiązania.

Część z config.yml:
Kod
doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #     path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true
        mappings:
            translatable:
                type: annotation
                alias: Gedmo
                prefix: Gedmo\Translatable\Entity
                # make sure vendor library location is correct
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"


Kod z services.yml:
Kod
parameters:
#    portal_cms.example.class: Portal\CmsBundle\Example

services:
    extension.listener:
        class: Portal\CmsBundle\EventListener\DoctrineExtensionListener
        calls:
            - [ setContainer, [ @service_container ] ]
        tags:
            # translatable sets locale after router processing
            - { name: kernel.event_listener, event: kernel.request, method: onLateKernelRequest, priority: -10 }
    gedmo.listener.sluggable:
        class: Gedmo\Sluggable\SluggableListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]
    gedmo.listener.translatable:
        class: Gedmo\Translatable\TranslatableListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]
            - [ setDefaultLocale, [ %locale% ] ]
            - [ setTranslationFallback, [ false ] ]
    
#    portal_cms.example:
#        class: %portal_cms.example.class%
#        arguments: [@service_id, "plain_value", %parameter%]


Kod z DoctrineExtensionListener.php:
  1. <?php
  2.  
  3. namespace Portal\CmsBundle\EventListener;
  4.  
  5. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  6. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  7. use Symfony\Component\DependencyInjection\ContainerInterface;
  8.  
  9. class DoctrineExtensionListener implements ContainerAwareInterface
  10. {
  11. /**
  12.   * @var ContainerInterface
  13.   */
  14. protected $container;
  15.  
  16. public function setContainer(ContainerInterface $container = null)
  17. {
  18. $this->container = $container;
  19. }
  20.  
  21. public function onLateKernelRequest(GetResponseEvent $event)
  22. {
  23. $translatable = $this->container->get('gedmo.listener.translatable');
  24. $translatable->setTranslatableLocale($event->getRequest()->getLocale());
  25. }
  26. }


Kod z encji Tag.php:
  1. <?php
  2.  
  3. namespace Portal\CmsBundle\Entity;
  4.  
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Gedmo\Translatable\Translatable;
  9.  
  10. /**
  11.  * Tag
  12.  *
  13.  * @ORM\Table()
  14.  * @ORM\Entity
  15.  */
  16. class Tag implements Translatable
  17. {
  18. /**
  19.   * @ORM\OneToMany(targetEntity="ArticleTag", mappedBy="tag")
  20.   */
  21. protected $articleTags;
  22.  
  23. public function __construct()
  24. {
  25. $this->articleTags = new ArrayCollection();
  26. }
  27.  
  28. /**
  29.   * @var integer
  30.   *
  31.   * @ORM\Column(name="id", type="integer")
  32.   * @ORM\Id
  33.   * @ORM\GeneratedValue(strategy="AUTO")
  34.   */
  35. private $id;
  36.  
  37. /**
  38.   * @var \DateTime
  39.   *
  40.   * @ORM\Column(name="created", type="datetime", nullable=true)
  41.   */
  42. private $created;
  43.  
  44. /**
  45.   * @var string
  46.   *
  47.   * @Gedmo\Translatable
  48.   * @Gedmo\Slug(fields={"name"})
  49.   * @ORM\Column(name="url", type="string", length=150, unique=true)
  50.   */
  51. private $url;
  52.  
  53. /**
  54.   * @var string
  55.   *
  56.   * @Gedmo\Translatable
  57.   * @ORM\Column(name="name", type="string", length=150)
  58.   */
  59. private $name;
  60.  
  61. /**
  62.   * @Gedmo\Locale
  63.   * Used locale to override Translation listener`s locale
  64.   * this is not a mapped field of entity metadata, just a simple property
  65.   */
  66. private $locale;
  67.  
  68. private $translations;
  69.  
  70.  
  71. /**
  72.   * Set created
  73.   *
  74.   * @param \DateTime $created
  75.   * @return Tag
  76.   */
  77. public function setCreated($created)
  78. {
  79. $this->created = $created;
  80.  
  81. return $this;
  82. }
  83.  
  84. /**
  85.   * Get created
  86.   *
  87.   * @return \DateTime
  88.   */
  89. public function getCreated()
  90. {
  91. return $this->created;
  92. }
  93.  
  94. /**
  95.   * Set url
  96.   *
  97.   * @param string $url
  98.   * @return Tag
  99.   */
  100. public function setUrl($url)
  101. {
  102. $this->url = $url;
  103.  
  104. return $this;
  105. }
  106.  
  107. /**
  108.   * Get url
  109.   *
  110.   * @return string
  111.   */
  112. public function getUrl()
  113. {
  114. return $this->url;
  115. }
  116.  
  117. /**
  118.   * Set name
  119.   *
  120.   * @param string $name
  121.   * @return Tag
  122.   */
  123. public function setName($name)
  124. {
  125. $this->name = $name;
  126.  
  127. return $this;
  128. }
  129.  
  130. /**
  131.   * Get name
  132.   *
  133.   * @return string
  134.   */
  135. public function getName()
  136. {
  137. return $this->name;
  138. }
  139.  
  140. /**
  141.   * Get id
  142.   *
  143.   * @return integer
  144.   */
  145. public function getId()
  146. {
  147. return $this->id;
  148. }
  149.  
  150. /**
  151.   * Set translations
  152.   *
  153.   * @param string $translations
  154.   * @return Tag
  155.   */
  156. public function setTranslations($translations)
  157. {
  158. $this->translations = $translations;
  159.  
  160. return $this;
  161. }
  162.  
  163. /**
  164.   * Get translations
  165.   *
  166.   * @return string
  167.   */
  168. public function getTranslations()
  169. {
  170. return $this->translations;
  171. }
  172.  
  173. /**
  174.   * Add articleTags
  175.   *
  176.   * @param \Portal\CmsBundle\Entity\ArticleTag $articleTags
  177.   * @return Tag
  178.   */
  179. public function addArticleTag(\Portal\CmsBundle\Entity\ArticleTag $articleTags)
  180. {
  181. $this->articleTags[] = $articleTags;
  182.  
  183. return $this;
  184. }
  185.  
  186. /**
  187.   * Remove articleTags
  188.   *
  189.   * @param \Portal\CmsBundle\Entity\ArticleTag $articleTags
  190.   */
  191. public function removeArticleTag(\Portal\CmsBundle\Entity\ArticleTag $articleTags)
  192. {
  193. $this->articleTags->removeElement($articleTags);
  194. }
  195.  
  196. /**
  197.   * Get articleTags
  198.   *
  199.   * @return \Doctrine\Common\Collections\Collection
  200.   */
  201. public function getArticleTags()
  202. {
  203. return $this->articleTags;
  204. }
  205.  
  206. public function setTranslatableLocale($locale)
  207. {
  208. $this->locale = $locale;
  209. }
  210. }
  211.  




Na forum jest jakiś błąd. Nie mogłem dodać całego tematu w jednym poście, bo był za długi. Próbuje resztę dodać w odpowiedzi, to dostaje komunikat że są błędy i pustą listę błędów.

Więc temat jest nie pełny, bo nie mam narazie możliwości dodania reszty

Generalnie część dokumentacji znajdująca się tutaj: https://github.com/Atlantic18/DoctrineExten...nslate-our-slug jest dla mnie nie do końca jasna. Czy kod:
  1. <?php
  2. $evm = new \Doctrine\Common\EventManager();
  3. $sluggableListener = new \Gedmo\Sluggable\SluggableListener();
  4. $evm->addEventSubscriber($sluggableListener);
  5. $translatableListener = new \Gedmo\Translatable\TranslationListener();
  6. $translatableListener->setTranslatableLocale('en_us');
  7. $evm->addEventSubscriber($translatableListener);
  8. // now this event manager should be passed to entity manager constructor

muszę gdzieś wstawiać, a jeśli tak to gdzie? Nie ma nigdzie takiej informacji. Z ciekawości wstawiłem go w kontrolerze w addAction i dostałem błąd, że nie można znaleźć \Gedmo\Translatable\TranslationListener(). I rzeczywiście w tej lokalizacji w Gedmo nie ma takiej klasy. Wogóle zapuściłem przeszukiwanie wszystkich plików w projekcie i nigdzie nie ma takiej klasy. Czy to pomyłka w dokumentacji, czy nie powinno tam być \Gedmo\Translatable\TranslatableListener() ?

Druga sprawa, czy pole na slug w encji i w bazie powinnu się nazywać 'slug'? U mnie nazywa się inaczej, jak widać, ale slug dla języka polskiego generuje się prawidłowo. Czy może to stanowić problem w wygenerowaniu sluga dla tłumaczeń?

Trzecia sprawa, czy konieczne jest dodanie w encji tych pól:
  1. <?php
  2. /**
  3.   * @ORM\Column(type="string", length=64)
  4.   */
  5. private $uniqueTitle;
  6.  
  7. /**
  8.   * @Gedmo\Slug(fields={"uniqueTitle"}, prefix="some-prefix-")
  9.   * @ORM\Column(type="string", length=128, unique=true)
  10.   */
  11. private $uniqueSlug;


Będę wdzięczny za wszelkie odpowiedzi, może coś naprowadzi mnie na rozwiązanie tego problemu.



No i nie udało mi się dodać kodu mojego kontrolera.

Cały temat tutaj: http://symfonylab.pl/forum/index.php/topic,613.0.html

Tam nie miałem problemu z dodaniem wszystkiego w jednym poście