0

I'm using A2lix translation form among with KNP Doctrine behaviors.

The fields are displayed correctly in the form and they're sent correctly as well (I've checked in the debug) but they're not saved in the database.

Here's my code:

Form Type

/**
     * Buildform function
     *
     * @param FormBuilderInterface $builder the formBuilder
     * @param array                $options the options for this form
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('code', 'text', [
                'required' => true,
            ])
            ->add('translations', 'a2lix_translations');
    }

Accesory entity

<?php

namespace SocialCar\CoreBundle\Entity;

use Knp\DoctrineBehaviors\Model as ORMBehaviors;

class Accessory
{
    use ORMBehaviors\Translatable\Translatable;

    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     */
    private $code;


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

    /**
     * Set code
     *
     * @param string $code
     * @return Accessory
     */
    public function setCode($code)
    {
        $this->code = $code;

        return $this;
    }

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

Accessory translation

<?php

namespace SocialCar\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;

/**
 * AccessoryTranslation
 */
class AccessoryTranslation
{
    use ORMBehaviors\Translatable\Translation;

    /**
     * @var string
     */
    private $name;


    /**
     * Set name
     *
     * @param string $name
     * @return AccessoryTranslation
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

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

Any ideas?

amdixon
  • 3,814
  • 8
  • 25
  • 34
petekaner
  • 8,071
  • 5
  • 29
  • 52

2 Answers2

1

Have you activate the knp translatable behavior in your config.yml file ?

knp_doctrine_behaviors:
    blameable:      ~
    geocodable:     ~     
    loggable:       ~
    sluggable:      ~
    soft_deletable: ~
    translatable:   true
0

You need to define relation between your entity and translation entity:

Accessory:

/**
 * @ORM\OneToMany(targetEntity="AccessoryTranslation", mappedBy="accessory", cascade={"persist", "remove"})
 */
protected $translations;

Accessory Translation:

/**
 * @ORM\ManyToOne(targetEntity="Accessory", inversedBy="translations")
 * @ORM\JoinColumn(name="accessory_id", referencedColumnName="id", onDelete="CASCADE")
 */
protected $object;
Michael Sivolobov
  • 12,388
  • 3
  • 43
  • 64
  • Thanks! but it looks like that should be already done in the traits. Besides, a2lix have a github repo with a demo and they don't include any of this, take a look: https://github.com/a2lix/Demo/blob/master/src/A2lix/DemoTranslationKnpBundle/Entity/CategoryTranslation.php – petekaner May 20 '15 at 14:36
  • are you sure about adding this info in the entities? This is included in the knp doctrine behaviours traits, isn't it? – petekaner May 27 '15 at 13:59