Hi, i will become crazy trying to use A2lixTranslation with AdminGenerator to translate my entities.
I will give you a lot of code to you have all the elements in your hand to be able to help me.
Im using Gedmo/translatable and is working ok, i make tests and if you create a entity is a controller and create some translations, Gedmo/translatable make the correct changes and insertion to BD.
im using symfony 2.3 and in composer.json i have this:
...
"cedriclombardot/admingenerator-user-bundle": "dev-master",
"cedriclombardot/admingenerator-generator-bundle": "2.3.*@dev",
"a2lix/translation-form-bundle": "dev-master",
...
I have a simple entity StaticText, and i want to translate one field. This is the code:
/**
* besmart\CoreBundle\Entity\StaticText
*
* @ORM\Entity
* @ORM\Table(name="static_text")
* @Gedmo\TranslationEntity(class="besmart\CoreBundle\Entity\Translation\StaticTextTranslation")
* @ORM\Entity(repositoryClass="besmart\CoreBundle\Repository\StaticTextRepository")
*/
class StaticText
{
...
/**
* @var text $description
* @Gedmo\Translatable
* @ORM\Column(name="description", type="text", nullable=true)
*/
protected $description;
/**
* @Gedmo\Locale
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
private $locale;
/**
* @ORM\OneToMany(targetEntity="besmart\CoreBundle\Entity\Translation\StaticTextTranslation",mappedBy="object", cascade={"persist", "remove"})
*/
private $translations;
public function getTranslations()
{
return $this->translations;
}
public function addTranslation(Translation\StaticTextTranslation $t)
{
if (!$this->translations->contains($t)) {
$this->translations[] = $t;
$t->setObject($this);
}
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
...
}
The StaticTextTranslation entity:
/**
* @ORM\Entity
* @ORM\Table(name="static_text_translations",
* uniqueConstraints={@ORM\UniqueConstraint(name="lookup_unique_idx", columns={
* "locale", "object_id", "field"
* })}
* )
*/
class StaticTextTranslation extends AbstractPersonalTranslation
{
/**
* Convinient constructor
*
* @param string $locale
* @param string $field
* @param string $value
*/
public function __construct($locale, $field, $value)
{
$this->setLocale($locale);
$this->setField($field);
$this->setContent($value);
}
/**
* @ORM\ManyToOne(targetEntity="besmart\CoreBundle\Entity\StaticText", inversedBy="translations")
* @ORM\JoinColumn(name="object_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $object;
}
This is my A2lixTranslationForm configuration in config.yml
a2lix_translation_form:
locales: [en] # [optional] Array of the translation locales (The default locale have to be excluded). Can also be specified in the form builder.
default_required: false # [optional] Defaults to false. In this case, translation fields are not mark as required with HTML5.
use_aop: true # [optional] Defaults to false.
And the admingenerator condiguration(in config.yml):
admingenerator_generator:
use_doctrine_orm: true
# thumbnail_generator: avalanche
dashboard_welcome_path: dashboard_admin
login_path: ~
logout_path: fos_user_security_logout
base_admin_template: AdmingeneratorGeneratorBundle::base_admin_assetic_less.html.twig
twig:
use_form_resources: true
use_localized_date: false
date_format: Y-m-d
datetime_format: Y-m-d H:i:s
localized_date_format: medium
localized_datetime_format: medium
number_format:
decimal: 0
decimal_point: .
thousand_separator: ,
In the StaticText-generator.yml i try this:
...
fields:
translations:
formType: a2lix_translations
and got this error(when try to access to "/new" route for StaticText) :
FatalErrorException: Error: Call to undefined method besmart\CoreBundle\Entity\StaticText::getTranslationEntityClass() in D:\docs\WORK\besmart\site\vendor\a2lix\translation-form-bundle\A2lix\TranslationFormBundle\TranslationForm\DefaultTranslationForm.php line 15
and then try this:
fields:
translations:
formType: a2lix_translations_gedmo
and got this error(when try to access to "/new" route for StaticText):
"Class does not exist"
Please, any help will be very appreciate, im not obliged to use gedmo\Translatable, if there is a better solution i adopt it.
Even better is a example of how to configure a complete use case, that´s something very important in the documentations.
Thanks in advance.