Undefined index: translationClass in GedmoTranslationForm

389 views Asked by At

I use

composer.json

"symfony/symfony": "2.6.*",
"doctrine/orm": "~2.2,>=2.2.3,<2.5",
"doctrine/dbal": "<2.5",
"doctrine/doctrine-bundle": "~1.2",
"stof/doctrine-extensions-bundle": "~1.1@dev",
"a2lix/translation-form-bundle": "1.*@dev",

config.yml

stof_doctrine_extensions:
    default_locale: en
    orm:
        default:
            translatable: true
            sluggable: true
            sluggable: true
            timestampable: true

a2lix_translation_form:
    #locale_provider: default       # [1]
    default_required: false
    locales: [de, pl,en]          # [1-a]
    manager_registry: doctrine      # [2]
    templating: "A2lixTranslationFormBundle::default.html.twig"      # [3]

Entity

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use APY\DataGridBundle\Grid\Mapping as GRID;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity
 * @ORM\Table(name="c_Coupon")
 * @Gedmo\TranslationEntity(class="CouponTranslation")
 */
class Coupon {

    /**
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Id
     */
    private $id;

    /**
     * @ORM\Column(length=8, unique=true)
     */

    private $name;

    /**
     * @ORM\Column(type="text", nullable=true )
     * @Gedmo\Translatable
     * @var string
     */
    private $description;



    /**
     * @GRID\Column(title="translations")
     * @ORM\OneToMany(
     *     targetEntity="CouponTranslation",
     *  mappedBy="object",
     *  cascade={"persist", "remove"}
     * )
     * @Assert\Valid(deep = true)
     */
    private $translations;

    public function __construct()
    {
        $this->translations = new \Doctrine\Common\Collections\ArrayCollection();
    }

    public function addTranslation(CountryTranslation $t)
    {
        if (!$this->translations->contains($t)) {
            $this->translations[] = $t;
            $t->setObject($this);
        }
    }


    /**
     * Set translations
     * @param ArrayCollection $translations
     * @return $this
     */
    public function setTranslations($translations)
    {
        foreach ($translations as $translation) {
            $translation->setObject($this);
        }

        $this->translations = $translations;
        return $this;
    }

    /**
     * Get translations
     *
     * @return ArrayCollection
     */
    public function getTranslations()
    {
        return $this->translations;
    }

CouponTranslation

<?php
namespace Mea\CharterBundle\Entity;
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation;
use Doctrine\ORM\Mapping as ORM;
/**

 * @ORM\Entity
 * @ORM\Table(name="c_coupon_translations",
 *   uniqueConstraints={@ORM\UniqueConstraint(name="lookup_unique_idx", columns={
 *     "locale", "object_id", "field"
 *   })}
 * )
 */
class CouponTranslation extends AbstractPersonalTranslation{
    /**
     * @ORM\ManyToOne(targetEntity="Coupon", inversedBy="translations")
     * @ORM\JoinColumn(name="object_id", referencedColumnName="id", onDelete="CASCADE")
     */
    protected $object;

    public function __construct($locale='', $field='', $value='')
    {
        if($locale)$this->setLocale($locale);
        if($field)$this->setField($field);
        if($value)$this->setContent($value);
    }

}

Form build

  $builder
            //->add('name')
            ->add('translations', 'a2lix_translations_gedmo', array(
                    'translatable_class' => "Mea\\CharterBundle\\Entity\\CouponTranslation",
                    'fields'=>array(
                        'name'=>array(),
                        'description'=>array(
                            'field_type' => 'ckeditor'
                        )
                    )
                )
            );

and get error Notice: Undefined index: translationClass in vendor/a2lix/translation-form-bundle/A2lix/TranslationFormBundle/TranslationForm/GedmoTranslationForm.php at line 57

1

There are 1 answers

0
Siim Kallari On

You are calling somewhere an array with a key 'translationClass', which is not defined. (Closest I see it is here:

'translatable_class' => "Mea\\CharterBundle\\Entity\\CouponTranslation",

but I do not know)

This thread should help you:

Reference - What does this error mean in PHP?