joaobarbosa
joaobarbosa

Reputation: 630

Doctrine Translatable class not found in chain in Symfony2

I'm having a problem using Translatable extension.

My composer.json is like this:

...
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "1.2.*",
"stof/doctrine-extensions-bundle": "@dev",
"gedmo/doctrine-extensions": "2.3.*@dev"
...

My config.yml is like this:

# Translatable Configuration
stof_doctrine_extensions:
    default_locale: br
    translation_fallback: true
    orm:
        default:
            tree: true
            translatable: true # not needed: listeners are not enabled by default

But when I try to make this call:

$translatable = $em->getRepository('Gedmo\\Translatable\\Entity\\Translation');

I've got this error:

The class 'Gedmo\Translatable\Entity\Translation' was not found in the chain configured namespaces Project\Portal\SampleBundle\Entity, Project\Portal\ExampleBundle\Entity, Project\Portal\CoreBundle\Entity

Does anyone knows whats happening and how can I fix it?

Thanks!

Upvotes: 0

Views: 2406

Answers (2)

Luke O'Sullivan
Luke O'Sullivan

Reputation: 110

Just for reference, you can also add the listners in your module configuration:

'doctrine' => array(
    ...
    'eventmanager' => array(
        'orm_default' => array(
            'subscribers' => array(
                'Gedmo\Sluggable\SluggableListener',
                'Gedmo\Timestampable\TimestampableListener',
                'Gedmo\SoftDeleteable\SoftDeleteableListener',
                'Gedmo\Loggable\LoggableListener',
                 ...
            ),
        ),
    ),
),

Upvotes: 0

Alex
Alex

Reputation: 12443

I had the same error but I'm using Zend Framework 2.

The missing piece was the doctrine driver for the translatable entities in my configuration:

<?php
return array(
    'doctrine' => array(
        'driver' => array(
            'base_entities' => array(
                'class' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                'cache' => 'array',
                'paths' => array(__DIR__ . '/../src/Base/Entity')
            ),
            // here
            'translatable_entities' => array(
                'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                'cache' => 'array',
                'paths' => array(__DIR__ . '/../../../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity')
            ),
            'orm_default' => array(
                'drivers' => array(
                    'Base\Entity' => 'base_entities',
                     // and here
                    'Gedmo\Translatable\Entity' => 'translatable_entities'
                )
            )
        )
    );

and don't forget to attach the TranslatableListener in your Module Bootstrap.

<?php

namespace Base;

use Zend\Mvc\ModuleRouteListener;

use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature;

class Module implements
    Feature\BootstrapListenerInterface {

    public function onBootstrap(EventInterface $e) {

        $sm = $e->getApplication()->getServiceManager();
        $em = $sm->get('doctrine.entitymanager.orm_default');
        $doctrineEventManager = $em->getEventManager();

        $translatableListener = new \Gedmo\Translatable\TranslatableListener();         
        $translatableListener->setDefaultLocale('de');
        $doctrineEventManager->addEventSubscriber($translatableListener);

Upvotes: 2

Related Questions