Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with A2lix and Generator Bundle #188

Closed
nicoip opened this issue Jul 31, 2015 · 12 comments
Closed

Issue with A2lix and Generator Bundle #188

nicoip opened this issue Jul 31, 2015 · 12 comments

Comments

@nicoip
Copy link

nicoip commented Jul 31, 2015

Hi everybody,

I have an issue with A2lx when its pluged with Generator Bundle.

I'm using Symfony 2.7.1.

I searched the solution long time and i didn't find an answer.

The A2lix's repository has nothing on it and it seems it take long time to have an answer to...

So i come to you, and hope that someone have a solution to well configure this two bundle to work together.

Her is the config.yml :

# A2lix
a2lix_translation_form:
    locale_provider: default       
    locales: [en, fr]          
    default_locale: %locale%             
    required_locales: [fr]
    manager_registry: doctrine
    templating: "A2lixTranslationFormBundle::default.html.twig"

# Doctrine Configuration
doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"                
        entity_managers:
            default:
                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"               

#AdminGenerator
admingenerator_generator:
    generator_cache: global_cache.provider
    # choose  and enable at least one
    use_propel:          false
    use_doctrine_orm:    true
    use_doctrine_odm:    false
    overwrite_if_exists: false
    base_admin_template: AdmingeneratorGeneratorBundle::base_uncompressed.html.twig
    #dashboard_welcome_path: root vers le dashboard de l'admin
    #dashboard_route:     MyDashboard_path
    generator_cache: global_cache.provider
    login_route: fos_user_security_login
    logout_route: fos_user_security_logout
    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: ,
    templates_dirs: []
    stylesheets: []
    javascripts: []

Here is the entity Admin.php (there is the field 'fonction' i want to translate) :

namespace Ip\AdminBundle\Entity;

use PUGX\MultiUserBundle\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;

use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;

use Gedmo\Translatable\Translatable;
use Ip\UserBundle\Entity\User as User;

/**
 * Admin
 *
 * @ORM\Table(name="admin")
 * @ORM\Entity(repositoryClass="Ip\AdminBundle\Entity\AdminRepository")
 * @UniqueEntity(fields = "username", targetClass = "Ip\UserBundle\Entity\User", message="fos_user.username.already_used")
 * @UniqueEntity(fields = "email", targetClass = "Ip\UserBundle\Entity\User", message="fos_user.email.already_used")
 * @Gedmo\TranslationEntity(class="Ip\AdminBundle\Entity\AdminTranslation")
 */
class Admin extends User implements Translatable 
{    
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @Gedmo\Locale
     * Used locale to override Translation listener`s locale
     * this is not a mapped field of entity metadata, just a simple property
     */
    protected $locale;

    /**
     * @var string
     * @Gedmo\Translatable
     * @ORM\Column(name="fonction", type="string", length=50, nullable=true)
     */
    private $fonction;  

    /**
     * @ORM\OneToMany(
     *     targetEntity="Ip\AdminBundle\Entity\AdminTranslation",
     *  mappedBy="object",
     *  cascade={"persist", "remove"}
     * )
     * @Assert\Valid(deep = true)
     */
    private $translations;

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

    /**
     * Set translations
     *
     * @param ArrayCollection $translations
     * @return Admin
     */
    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;
    }  

    public function setTranslatableLocale($locale)
    {
        $this->locale = $locale;
    }

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

    /**
     * Set fonction
     *
     * @param string $fonction
     * @return Admin
     */
    public function setFonction($fonction)
    {
        $this->fonction = $fonction;

        return $this;
    }

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

    public function _toString(){

        return $this->prenom.' '.$this->nom;

    }

}

Here is the class AdminTranslation :

namespace Ip\AdminBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation;

/**
 * Entity\AdminTranslation.php

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

And the Admin-generator.yml :

generator: admingenerator.generator.doctrine
params:
    model: Ip\AdminBundle\Entity\Admin
    namespace_prefix: Ip
    concurrency_lock: ~
    bundle_name: AdminBundle
    pk_requirement: ~
    fields:  
      translations:
        formType: a2lix_translations
        label: Fonction 
        addFormOptions:
         locales: [fr, en]
         required: false
         fields: 
           fonction:
             locale_options:
               en:
                 label : Function    
               fr:
                 label : Fonction                     

    object_actions:
        delete: ~
    batch_actions:
        delete: ~

stylesheets:
   - bundles/a2lixtranslationform/css/a2lix_translation.css
javascripts:
   - /bundles/a2lixtranslationform/js/a2lix_translation.js   

builders:
    list:
        params:
            title: List for AdminBundle
            display: [id, fonction]
            actions:
                new: ~
            object_actions:
                edit: ~
                delete: ~
    new:
        params:
            title: New object for AdminBundle
            display: [id, fonction, translations]
            actions:
                save: ~
                list: ~
    edit:
        params:
            title: "You're editing the object \"%object%\"|{ %object%: Admin.fonction}|"
            display: [id, fonction, translations]
            actions:
                save: ~
                list: ~
    show:
        params:
            title: "You're viewing the object \"%object%\"|{ %object%: Admin.fonction}|"
            display: [id, fonction, translations]
            actions:
                list: ~
                new: ~

    actions:
        params:
            object_actions:
                delete: ~
            batch_actions:
                delete: ~

    filters:
        params:
            display: [id, username, email, password]

If someone could help me...

thanks a lot !

@ksn135
Copy link
Contributor

ksn135 commented Jul 31, 2015

Well, take a look at my configs:

    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "~2.7@beta",
        "symfony2admingenerator/generator-bundle": "dev-master",
        "symfony2admingenerator/form-extensions-bundle": "dev-master",
        "symfony2admingenerator/user-bundle": "dev-master",
        "friendsofsymfony/user-bundle": "~2.0@dev",
        "a2lix/translation-form-bundle": "1.*@dev"
    }
a2lix_translation_form:
    locales:                       [ru,en]
    default_required:              true  
    manager_registry:              doctrine
    templating:                    "A2lixTranslationFormBundle::default.html.twig"  
generator: admingenerator.generator.doctrine
params:
    model: AppBundle\Entity\NewsItem
    concurrency_lock: ~
    bundle_name: AppBundle
    pk_requirement: \d+
    actionAfterSave:    show  
    i18n_catalog:       messages  
    custom_blocks:      AppBundle:Form:custom_blocks.html.twig    
    fields: 

        content:
            label:             news.item.content
            customView:        nl2br
            addFormOptions:
                required:       true 
        published:
            label:             news.item.published
        publishedAt:
            label:             news.item.publishedAt
            dbType:            datetime
            formType:          s2a_datetime_picker
            addFormOptions:
                required:      false
        publishedBy:
            label:             news.item.publishedBy
        category:
            label:             news.item.category
            sortOn:            category.title
            addFormOptions:
                query_builder:  function (\Doctrine\ORM\EntityRepository $repository) { return $repository->createQueryBuilder("c")->orderBy("c.title", "ASC"); }
                required:       true 
        title:
            label:              global.title            
            addFormOptions:
                required:       true 
        translations:
            label:              global.translations            
            formType:           a2lix_translations_gedmo
            addFormOptions:
                fields:
                    title:                    
                        label:  global.title    

    object_actions:
        delete: 
            credentials: 'hasRole("ROLE_NEWS")'  
    batch_actions:
        delete: 
            credentials: 'hasRole("ROLE_NEWS")'  
builders:
    list:
        params:
            fields:
                published:
                    label:   ?
            title:           news.item.list.title
            sort:            [publishedAt, desc]       
            display:   
                -             publishedAt
                -             title
                -             category
                -             published
            actions:
                new:   
                    credentials: 'hasRole("ROLE_NEWS")'  
            object_actions:
                show:  ~ 
                edit: 
                    credentials: 'hasRole("ROLE_NEWS")'  
    excel:
        params: 
            credentials: 'hasRole("ROLE_SUPER_PUPER")'  
        filename: ~
        filetype: ~
    new:
        params:
            credentials: 'hasRole("ROLE_NEWS")'  
            title:              news.item.new.title
            display:            [published, category, title, content]
            actions:
                save: 
                    credentials: 'hasRole("ROLE_NEWS")'  
                list: ~
    edit:
        params:
            credentials: 'hasRole("ROLE_NEWS")'  
            title:              news.item.edit.title
            display:            [published, category, translations]
            actions:
                save: 
                    credentials: 'hasRole("ROLE_NEWS")'  
                delete: 
                    credentials: 'hasRole("ROLE_NEWS")'  
                list: ~
    show:
        params:
            title:              "%title%|{ %title%: NewsItem.title }|"
            display:            
                -               category
                -               content
                -               published

            actions:
                list: ~
                edit: 
                    credentials: 'hasRole("ROLE_NEWS")'  
    actions:
        params:
            object_actions:
                delete: 
                    credentials: 'hasRole("ROLE_NEWS")'  
            batch_actions:
                delete: 
                    credentials: 'hasRole("ROLE_SUPER_PUPER")'  

screen shot 2015-07-31 at 16 50 10

@nicoip
Copy link
Author

nicoip commented Jul 31, 2015

Hi ksn135,

thank you :)

With your config, :

Could not load type "a2lix_translations_gedmo"

Whate Strategie use you and what version ?

thank you

@ksn135
Copy link
Contributor

ksn135 commented Jul 31, 2015

@nicoip First of all check version a2lix. It must be 1.4 branch
composer require "a2lix/translation-form-bundle": "1.*@dev"
And I use GedmoDoctrineExtension implementation from @stof
composer require "stof/doctrine-extensions-bundle": "~1.1@dev"

@nicoip
Copy link
Author

nicoip commented Jul 31, 2015

@ksn135,

My new config :

        "php": ">=5.3.9",
        "symfony/symfony": "2.7.3",
        "doctrine/orm": "~2.2,>=2.2.3,<2.5",
        "doctrine/dbal": "<2.5",
        "doctrine/doctrine-bundle": "~1.4",
        "symfony/assetic-bundle": "~2.3",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~4.0",
        "sensio/framework-extra-bundle": "~3.0,>=3.0.2",
        "incenteev/composer-parameter-handler": "~2.0",

        "symfony2admingenerator/generator-bundle": "^2.0@beta",
        "pimple/pimple": "~3.0",
        "liuggio/excelbundle": "2.*",
        "symfony2admingenerator/form-extensions-bundle": "dev-master",
        "liip/imagine-bundle": "1.3.*",
        "symfony2admingenerator/user-bundle": "dev-master",
        "friendsofsymfony/user-bundle": "~2.0@dev",
        "pugx/multi-user-bundle": "3.0.*@dev",
        "vich/uploader-bundle": "dev-master",
        "stof/doctrine-extensions-bundle": "~1.1@dev",
        "a2lix/translation-form-bundle": "1.*@dev",
        "doctrine/doctrine-fixtures-bundle": "dev-master",
        "egeloen/ckeditor-bundle": "~2.0",
    "gregwar/captcha-bundle": "dev-master"

And always

Could not load type "a2lix_translations_gedmo"

@nicoip
Copy link
Author

nicoip commented Jul 31, 2015

@ksn135
Can you show your two class entities NewsItem and NewsItemTranslation please ?

Thank you

@ksn135
Copy link
Contributor

ksn135 commented Jul 31, 2015

Your entities are just fine. Just guessing:

  1. Do you add constructors in your AppKernel.php file ?
// in AppKernel::registerBundles()
$bundles = array(
// ...
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
            new A2lix\TranslationFormBundle\A2lixTranslationFormBundle(),
// ...
);
  1. Do you setup in your config.yml required parameters ?
stof_doctrine_extensions:
    default_locale:                  "%locale%"
    translation_fallback:            true
    persist_default_translation:     true
    class:
        sluggable:                   AppBundle\Listener\SluggableListener
    orm:
        default:
            timestampable:           true
            sortable:                true
            blameable:               true
            sluggable:               true
            tree:                    true
            softdeleteable:          true
            translatable:            true  ############ <= ENABLE THIS !!!
doctrine:
    dbal:
        driver:                     pdo_mysql
        host:                       "%database_host%"
        port:                       "%database_port%"
        dbname:                     "%database_name%"
        user:                       "%database_user%"
        password:                   "%database_password%"
        charset:                    UTF8
        options:
            1002:                   "SET NAMES 'UTF8' COLLATE 'utf8_general_ci'"  
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        entity_managers:
            default:        
                dql:
                    string_functions:
                        ifnull:      DoctrineExtensions\Query\Mysql\IfNull
                    datetime_functions:
                        date:        Luxifer\DQL\Datetime\Date
                        year:        Luxifer\DQL\Datetime\Year
                        month:       Luxifer\DQL\Datetime\Month
                auto_mapping:        true
                mappings:
                    gedmo_tree:
                        type:        annotation
                        prefix:      Gedmo\Tree\Entity
                        dir:         "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
                        alias:       GedmoTree # this one is optional and will default to the name set for the mapping
                        is_bundle:   false

##########################################################################
                    gedmo_translatable:  ######## <= CHECK THIS BLOCK !!!!
                        type:        annotation
                        prefix:      Gedmo\Translatable\Entity
                        dir:         "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
                        alias:       GedmoTranslatable # this one is optional and will default to the name set for the mapping
                        is_bundle:   false
                    gedmo_translator:   ######## <= AND THIS ONE !!!!
                        type:        annotation
                        prefix:      Gedmo\Translator\Entity
                        dir:         "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Entity"
                        alias:       GedmoTranslator # this one is optional and will default to the name set for the mapping
                        is_bundle:   false

##########################################################################

                    gedmo_loggable:
                        type:        annotation
                        prefix:      Gedmo\Loggable\Entity
                        dir:         "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity"
                        alias:       GedmoLoggable # this one is optional and will default to the name set for the mapping
                        is_bundle:   false                        
                filters:
                    softdeleteable:
                        class:       Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
                        enabled:     true
  1. Do you include doctrine listeners into your service.yml ?
# app/config/doctrine-extensions.yml
# services to handle doctrine extensions
# import it in config.yml
services:

##############################################################################
    # KernelRequest listener
    extension.listener:
        class: AppBundle\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.translatable:
        class: Gedmo\Translatable\TranslatableListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]
            - [ setDefaultLocale, [ %locale% ] ]
            # - [ setTranslatableLocale, [ %locale% ] ]
            - [ setTranslationFallback, [ true ] ]

##############################################################################

#### the rest are not important, you can remove them 
    gedmo.listener.tree:
        class: Gedmo\Tree\TreeListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ @annotation_reader ] ]

    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 ] ]
  1. And last but not least: did you clear the cache after above steps ? )

@ksn135
Copy link
Contributor

ksn135 commented Jul 31, 2015

Also, I strongly advise you to read this

@ksn135
Copy link
Contributor

ksn135 commented Jul 31, 2015

And yes, my entities is here

@nicoip
Copy link
Author

nicoip commented Jul 31, 2015

@ksn135 Thank You,

Now i have

/admin/new

Attempted to call an undefined method named "getTranslationEntityClass" of class "Ip\AdminBundle\Entity\Admin".

and

/admin/ (list)
An exception has been thrown during the rendering of a template ("[Semantical Error] line 0, col 55 near 'translations': Error: Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected.") in Admingenerated/IpAdminBundle/Resources/views/AdminList/results.html.twig at line 6.

I always clear my cache...

@ksn135
Copy link
Contributor

ksn135 commented Jul 31, 2015

Well, try to add new function to your class Ip\AdminBundle\Entity\Admin:

class Admin {
    /*...*/
    public function getTranslationEntityClass() { return "Ip\AdminBundle\Entity\AdminTranslation"; }
}

Let's see what's happens next )

BTW: I'm absolutely sure that you are using a wrong version of Gdemo or A2lix bundle.

@nicoip
Copy link
Author

nicoip commented Jul 31, 2015

ok
I'll check everything

composer require "a2lix/translation-form-bundle": "1.*@dev"
And I use GedmoDoctrineExtension implementation from @stof
composer require "stof/doctrine-extensions-bundle": "~1.1@dev"

Thank you !!

@nicoip
Copy link
Author

nicoip commented Aug 3, 2015

it works!

a big thank you

@nicoip nicoip closed this as completed Aug 3, 2015
@pjam pjam mentioned this issue Nov 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants