a2lix / TranslationFormBundle

Ease translations with some dedicated Symfony form types
https://a2lix.fr/bundles/translation-form
MIT License
331 stars 138 forks source link

Notice: Undefined index: translationClass A2lix/TranslationFormBundle/TranslationForm/GedmoTranslationForm.php #68

Closed ghost closed 11 years ago

ghost commented 11 years ago

In Sonata admin panel I got an error:

Notice: Undefined index: translationClass in /var/www/.../vendor/a2lix/translation-form-bundle/A2lix/TranslationFormBundle/TranslationForm/GedmoTranslationForm.php line 57

my Admin class:

 $formMapper
    ->add('translations', 'a2lix_translations_gedmo', array(
        'translatable_class' => 'Ticket\Bundle\FrontendBundle\Entity\Event',
        'fields' => array(
            'title' => array(
                'type' => 'text'
            ),
            'description' => array(
                'type' => 'textarea'
            )
        )
    ))
;
webda2l commented 11 years ago

This bundle need that you have beforehand a well configured strategy (Gedmo or other). It appear that yours is not right. For Gedmo, you should read https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/translatable.md#personal-translations / https://github.com/stof/StofDoctrineExtensionsBundle/blob/master/Resources/doc/index.rst / http://www.elao.com/blog/symfony-2/doctrine-2/how-to-manage-translations-for-your-object-using-sonataadminbundle.html / http://vincent.composieux.fr/article/manipulez-des-traductions-avec-doctrine-gedmo-translatable. For mine, http://a2lix.fr/bundles/i18n-doctrine/

I always plan to write some blog posts for each existing strategy... one day.

ghost commented 11 years ago

I checked my configuration, but still cannot get it working. So I just used http://a2lix.fr/bundles/i18n-doctrine/

Thanks!

webda2l commented 11 years ago

Fine, if you need the fallback functionality, you'll can switch to knplabs strategy or, later when it'll be finish, the gedmo wip2.4 branch, without change about your database.

ghost commented 11 years ago

How can I show list of entity fields in sonata admin? It is not mentioned in tutorial http://a2lix.fr/bundles/i18n-doctrine/

Should I do something like this this:

protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->addIdentifier('id')
        ->add('translations.name')
        ->add('description');
    ;
}
webda2l commented 11 years ago

I don't use Sonota for a while and not with this I18nDoctrineBundle..

protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->addIdentifier('id')
        ->add('name')
        ->add('description');
    ;
}

don't work ?

ghost commented 11 years ago

No, it doesn't

Can someone write me a link for knplabs strategy?

webda2l commented 11 years ago

https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/master/Model/ModelManager.php#L473. It appear that Sonata read only properties, so "translations['XX'].name" where "XX" is your locale maybe.

You'll have the same problem with knplabs strategy but you can ask them if they test their translatable feature with sonata. https://github.com/KnpLabs/DoctrineBehaviors/issues

ghost commented 11 years ago

Can someone explain more about the gedmo wip2.4 branch? What is this and then it will be done?

ghost commented 11 years ago

I tried this:

->add("translations['en'].name")

but it doesn't work

The solution can be next: In the entity class we need to add new methods, like:

public function getName()
{
    $translations = $this->getTranslations();
    return isset($translations['en']) ? $translations['en']->getName() : null;
}

and in ListMapper use simple:

->add('name')
webda2l commented 11 years ago

The modelManager of sonata should use the properyAccess component, it'll be better. http://symfony.com/blog/new-in-symfony-2-2-new-propertyaccess-component. For now you can use your method yes.

You can use the $this->getCurrentTranslation() too if you don't have see it.

ghost commented 11 years ago

19th of September the gedmo wip2.4.0 was out https://packagist.org/packages/gedmo/doctrine-extensions And it works like charm! I highly recommend it.

pdias commented 11 years ago

IProphet I know this is not the right place to put this question, but I installed version wip2.4.0 and kept the settings used for the master version ... but now I get a lot of errors ... can you provide a config for this version (wip 2.4.0)?

Thanks.

webda2l commented 11 years ago

I postponed again a blog post, sorry... But here some tips:

1/ In composer.json:

 "gedmo/doctrine-extensions": "dev-wip-v2.4.0"

2/ In config.yml

doctrine:
    dbal:
...
    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true
        mappings:
            translatable:
                type: annotation
                alias: Gedmo
                prefix: Gedmo\Translatable\Entity
                # make sure vendor library location is correct
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity/MappedSuperclass"

3/ Activate https://github.com/a2lix/TranslationFormBundle/blob/master/Util/Gedmo/config/gedmo.xml. Different way, but simplest is copy/paste in your app/config and import it as resource

4/ See example of entities from https://github.com/a2lix/TranslationFormBundle/blob/master/Tests/Gedmo/Fixtures/Entity/Product.php and https://github.com/a2lix/TranslationFormBundle/blob/master/Tests/Gedmo/Fixtures/Entity/ProductTranslation.php

pdias commented 11 years ago

Thank you, but I have a small question concerning wip 2.4.0.

In previous versions (in doctrine extensions) I create a doctrine_extensions.yml...

services:
    # KernelRequest listener
    extension.listener:
        class: MainBundle\Listener\DoctrineExtensionListener
        calls:
            - [ setContainer, [ @service_container ] ]
        tags:
            # translatable sets locale after router processing
            - { name: kernel.event_listener, event: kernel.request, method: onLateKernelRequest, priority: -10 }
            # loggable hooks user username if one is in security context
            - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }

    # Doctrine Extension listeners to handle behaviors
    gedmo.listener.tree:
        class: Gedmo\Tree\TreeListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]

    gedmo.listener.translatable:
        class: Gedmo\Translatable\TranslatableListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]
            - [ setDefaultLocale, [ %default_locale% ] ]
            - [ setTranslationFallback, [ true ] ]

    gedmo.listener.timestampable:
        class: Gedmo\Timestampable\TimestampableListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]

    gedmo.listener.sluggable:
        class: Gedmo\Sluggable\SluggableListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]

    gedmo.listener.sortable:
        class: Gedmo\Sortable\SortableListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]

    gedmo.listener.loggable:
        class: Gedmo\Loggable\LoggableListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]

My question, thinking this continues to be necessary, the file remains like this or is changed. If I must change how should I proceed?

Sorry to bother you with this.

daichihaji commented 9 years ago

Hi I hit the quite the same problem with @proph7

and now I am trying to introduce gedmo wip2.4.0 suggested by @iprophet.

however stof/doctrine-extensions-bundle requires gedmo 2.3.*

these are my current setting.

    "a2lix/translation-form-bundle": "1.3", 
    "stof/doctrine-extensions-bundle" :  "dev-master",
     "gedmo/doctrine-extensions":      "2.3.12",

Even latest stof/doctrine-extensions-bundle doesnt accept gedmo wip 2.4.0