15

私はエンティティを gedmo 教義の拡張で翻訳しようとしています。

https://github.com/Atlantic18/DoctrineExtensions

orm マッピング ファイル (自動生成エンティティ) として yml を使用しています。

orm.yml:

CS\ContentBundle\Entity\Post:
  type:  entity
  table: posts
  repositoryClass: CS\ContentBundle\Entity\PostRepository
  gedmo:
    soft_deleteable:
      field_name: deleted_at
    translation:
      locale: locale
  fields:
    id:
      type: integer
      length: 11
      id: true
      generator:
        strategy: AUTO
    title:
      type: string
      length: 500
      gedmo:
        - translatable
    slug:
      type: string
      length: 500
      gedmo:
        translatable: {}
        slug:
          separator: -
          fields:
            - title

タイトルは問題なく翻訳できます。しかし、スラッグは機能していません...

通常、デフォルトの言語 (tr) では、自分で生成処理を行わずにスラッグを自動生成します。

エンティティ ファイル:

<?php

namespace CS\ContentBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Translatable;
use Gedmo\Mapping\Annotation as Gedmo;
use APY\DataGridBundle\Grid\Mapping as GRID;

/**
 * Post
 * @Gedmo\SoftDeleteable(fieldName="deleted_at", timeAware=false)
 * @GRID\Source(columns="id,title,is_active,created_at,updated_at")
 */
class Post implements Translatable
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     * @Gedmo\Translatable
     * @GRID\Column(title="Başlık", filterable=true)
     */
    private $title;

    /**
     * @var string
     * @Gedmo\Translatable
     */
    private $slug;

    /**
     * @Gedmo\Locale
     */
    private $locale;

    public function setLocale($locale)
    {
        $this->locale = $locale;
    }


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set title
     *
     * @param string $title
     * @return Post
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

    /**
     * Get title
     *
     * @return string 
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * Set slug
     *
     * @param string $slug
     * @return Post
     */
    public function setSlug($slug)
    {
        $this->slug = $slug;

        return $this;
    }

    /**
     * Get slug
     *
     * @return string 
     */
    public function getSlug()
    {
        return $this->slug;
    }
}

ドキュメントの一部があります: https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/sluggable.md#using-translationlistener-to-translate-our-slug

これらのリスナーを適用する方法がわかりません。

スラッグを自動的に翻訳するにはどうすればよいですか?


編集

doctrine と stof_doctrine_extensions の私の config.yml:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   "%database_driver%"
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
                mapping_types:
                  enum: string
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true
        metadata_cache_driver: redis
        query_cache_driver: redis
        filters:
            softdeleteable:
                class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
                enabled: true
        mappings:
            StofDoctrineExtensionsBundle: ~
            gedmo_translatable:
                type: annotation
                prefix: Gedmo\Translatable\Entity
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
                alias: GedmoTranslatable # this one is optional and will default to the name set for the mapping
                is_bundle: false
            gedmo_tree:
                type: annotation
                prefix: Gedmo\Tree\Entity
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
                alias: GedmoTree # this one is optional and will default to the name set for the mapping
                is_bundle: false

stof_doctrine_extensions:
    default_locale: "%locale%"
    translation_fallback: true
    orm:
        default:
            tree: true
            sluggable: true
            translatable: true
            timestampable: true
            softdeleteable: true
4

4 に答える 4

1

あなたの設定は正しいように見えます。ただし、ベンダーを更新しようとしましたか? 一部のファイルが破損している可能性があります。

更新プロセスが機能しない場合は、構成を私のものと完全に比較していただけますか:

doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true
        dql:
            string_functions:
                GroupConcat: DoctrineExtensions\Query\Mysql\GroupConcat
                IF: DoctrineExtensions\Query\Mysql\IfElse
        filters:
            softdeleteable:
                class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
                enabled: true
        mappings:
            StofDoctrineExtensionsBundle: ~
            gedmo_tree:
                type: annotation
                prefix: Gedmo\Tree\Entity
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
                alias: GedmoTree
                is_bundle: false
            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"

また、services.yml でgedmo.listener.translatableをオーバーライドしないようにしてください。デフォルトのものをオーバーライドするコードがある場合は、それを削除してください。デフォルト設定:

gedmo.listener.translatable:
        class: Gedmo\Translatable\TranslatableListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]
            - [ setDefaultLocale, [ %locale% ] ]
            - [ setTranslationFallback, [ false ] ]
于 2014-12-29T20:55:17.910 に答える
1

私にとって奇妙なこと:エンティティによるORM構成は2つのファイル(yamlと注釈)で行われますか?

リスナーは、適切な順序で適切にロードされているように見えます。多分それはエンティティフィールドの設定ですorm.yml。フィールドで翻訳可能とスラッグ可能を反転してみてくださいslug:

CS\ContentBundle\Entity\Post:
  type:  entity
  table: posts
  repositoryClass: CS\ContentBundle\Entity\PostRepository
  gedmo:
    soft_deleteable:
      field_name: deleted_at
    translation:
      locale: locale
  fields:
    id:
      type: integer
      length: 11
      id: true
      generator:
        strategy: AUTO
    title:
      type: string
      length: 500
      gedmo:
        - translatable
    slug:
      type: string
      length: 500
      gedmo:
        slug:
          separator: -
          fields:
            - title
        translatable: {}
于 2014-12-24T14:57:22.097 に答える