No translation form found with default entity translations

I am trying to create a translation translation form

http://a2lix.fr/bundles/translation-form/ and https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/translatable.md#translatable-entity-example

composer.json

    "a2lix/translation-form-bundle": "2.*@dev",
    "stof/doctrine-extensions-bundle": "1.2.*@dev",

      

config.yml

stof_doctrine_extensions: default_locale: en ORM: default: translitable: true sluggable: true sluggable: true timestampable: true

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

      

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 Gedmo\Translatable\Translatable;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity
 * @ORM\Table(name="c_Base"
    ,indexes={
 *      @ORM\Index(name="search_name", columns={"name"}),
 *      @ORM\Index(name="orderCity", columns={"city"})
 * })
 */
class Base  implements Translatable{

    /**
     * @ORM\Column(type="bigint")
     * @ORM\Id
     */
    private $id;

    /**
     * Hexaid
     * @var string
     */
    private $hid;

    /**
     * @ORM\Column(type="string")
     * @GRID\Column(title="name")
     * @Gedmo\Translatable
     * @var string
     */
    private $name;

    /**
     * @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;

      

build a shape

public function buildForm (FormBuilderInterface $ builder, array $ options) {

    $builder

        ->add('translations', 'a2lix_translations', array(
                'fields'=>array(
                    'name'=>array(),
                    'description'=>array(
                        'field_type' => 'ckeditor'
                    )
                )
            )
        );

      

mistake

Neither the property "translations" nor one of the methods "getTranslations()", "translations()", "isTranslations()", "hasTranslations()", "__get()" exist and have public access in class "Mea\CharterBundle\Entity\Base".

      

I won't have private $ translations; var in the database - because there is a public translation - in the example for personal translations there are $ translations https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/translatable.md#personal-translations

but there is no for https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/translatable.md#translatable-entity-example .

Can I use it at http://a2lix.fr/bundles/translation-form/ ?

here's another example DoctrineExtensions Notification: Undefined index: foreignKey in $ em-> getRepository ('Gedmo \\ Translatable \\ Entity \\ Translation');

+3


source to share


1 answer


Here's a working example from my current project of how to use the DoctrineExtension from KNP (I know this doesn't answer the question, see comments above).

composer.json:

"knplabs/doctrine-behaviors": "dev-master",
"a2lix/translation-form-bundle" : "dev-master"

      

config.yml:

imports:
    ...
    - { resource: ../../vendor/knplabs/doctrine-behaviors/config/orm-services.yml }

framework:
    translator:
        fallback: "%locale%"
    ...

a2lix_translation_form:
    locale_provider: default
    locales: [ru, en]
    default_locale: ru
    required_locales: [ru]
    manager_registry: doctrine
    templating: "@SLCore/includes/translation.html.twig" # if you want to use your own template 

      

Essence: Product

use Knp\DoctrineBehaviors\Model\Translatable\Translatable;

class Product
{
    use Translatable;

    // other fields which should not be translated
    // $translations field alredy has been created and mapped by DE

      



ProductTranslation (DE requires this entity):

use Knp\DoctrineBehaviors\Model\Translatable\Translation;

class ProductTranslation
{
    use Translation;

    // fields that should be translated
    // e.g. $title, $description (id, locale, translatable fields already have been created by Translation trait, mapped by DE)

      

ProductType Form:

->add('translations', 'a2lix_translations', [/* other options go here */])

      

form.html.twig:

{% block javascripts %}
    {{ parent() }}
    <script type="text/javascript" src="{{ asset('bundles/a2lixtranslationform/js/a2lix_translation_bootstrap.js') }}"></script>
{% endblock %}

...

{{ form_widget(form.translations) }}

      

I know this is not an interesting example, but it works.

+2


source







All Articles