stof / StofDoctrineExtensionsBundle

Integration bundle for DoctrineExtensions by l3pp4rd in Symfony
https://symfony.com/bundles/StofDoctrineExtensionsBundle/current/index.html
MIT License
1.89k stars 380 forks source link

Translatable doesn't work #322

Open yannissgarra opened 8 years ago

yannissgarra commented 8 years ago

Hi ! I try to use Doctrine Extension Translatable, but it doesn't work.

So, this is my configuration :

In my composer

"stof/doctrine-extensions-bundle": "^1.2"

In my config.yml

doctrine:
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            gedmo_translatable:
                type: annotation
                prefix: Gedmo\Translatable\Entity
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
                alias: GedmoTranslatable
                is_bundle: false

stof_doctrine_extensions:
    default_locale: en
    translation_fallback: true
    orm:
        default:
            translatable: true

My Shop Class

<?php

namespace ShopBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;

/**
 * Shop implements Translatable
 *
 * @ORM\Table(name="shop")
 * @ORM\Entity(repositoryClass="ShopBundle\Repository\ShopRepository")
 */
class Shop
{
    /**
     * @var string
     *
     * @Gedmo\Translatable
     * @ORM\Column(name="description", type="string", length=255)
     */
    private $description;

    /**
     * @var string
     * 
     * @Gedmo\Locale
     */
    private $local;

    /**
     * Set description
     *
     * @param string $description
     * @return Shop
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

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

    /**
     * Set translatable local
     *
     * @param string $locale
     * @return Shop
     */
    public function setTranslatableLocale($locale)
    {
        $this->locale = $locale;

        return $this;
    }
}

My Fixtures

<?php

namespace GeographyBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use ShopBundle\Entity\Shop;

/**
 * Load Shop Data
 */
class LoadShopData extends AbstractFixture implements OrderedFixtureInterface
{
    /**
     * Load
     *
     * @param \Doctrine\Common\Persistence\ObjectManager $manager
     */
    public function load(ObjectManager $manager)
    {
        $shop = new Shop();
        $shop->setDescription('This is shop 1 !');
        $manager->persist($shop);
        $manager->flush();

        $shop->setTranslatableLocale('fr');
        $shop->setDescription("Ceci est le shop 1 !");
        $manager->flush();
    }
}

Table ext_translation was created on php app/console doctrine:schema:create, but no data was insert on php app/console doctrine:fixtures:load and description field was juste updated on shop table.

What's wrong with my code ?

Thanks for any help.

FireLizard commented 7 years ago

Same here! :(

The Solution on Stackoverflow doesn't work, too.

Is there anybody who is maintaining this bundle, @stof ?

fabpico commented 1 month ago

Did you try to update the package? Does it happen also outside of the fixture context? What packages have you installed in composer.json? With version 1.12.0 on Symfony 6.4 and Doctrine ORM 3.2.2 it's working so far (still initial write/read testing).