Api 平台在实体继承中没有得到翻译

时间:2021-02-19 21:42:02

标签: symfony doctrine-orm api-platform.com doctrine-extensions

我在实现 Gedmo\Translatable\Translatable 的学说中有类继承,

如果我自己获取数据,或者使用其他第三方库(如 EasyAdmin),它会根据 Accept-Language 标头正常工作。但是使用 api 平台我总是得到默认的。 对于没有类继承的任何其他实体,如果它有效。

这个例子在子类中实现了 Translatable,但我也在父类中尝试过。

我的配置是:

# config/packages/stof_doctrine_extensions.yaml
stof_doctrine_extensions:
    default_locale: '%locale%'
    translation_fallback: true
    persist_default_translation: true
    orm:
        default:
            timestampable: true
            sluggable: true
            blameable: true
            translatable: true
<?php

namespace App\Entity;

use App\Repository\GreetingRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * @ORM\Entity(repositoryClass=GreetingRepository::class)
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="type", type="integer")
 * @ORM\DiscriminatorMap({
 *  0 = "App\Entity\Greeting",
 *  1 = "App\Entity\Hello",
 * })
 */
class Greeting
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    protected $id;

    /**
     * @ORM\Column(type="string", length=255)
     * @Gedmo\Translatable
     */
    protected $title;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getTitle(): ?string
    {
        return $this->title;
    }

    public function setTitle(string $title): self
    {
        $this->title = $title;

        return $this;
    }
}

<?php

namespace App\Entity;

use App\Repository\HelloRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Translatable;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * @ORM\Entity(repositoryClass=HelloRepository::class)
 */
class Hello extends Greeting implements Translatable
{
    /**
     * @ORM\Column(type="string", length=255)
     * @Gedmo\Translatable
     */
    protected $form;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getForm(): ?string
    {
        return $this->form;
    }

    public function setForm(string $form): self
    {
        $this->form = $form;

        return $this;
    }
}

0 个答案:

没有答案
相关问题