Closed yooper closed 7 years ago
This would be very helpful!
In the mean time, how would go about using the Doctrine Extensions inside Laravel ?
I've required the package, "gedmo/doctrine-extensions": "2.3.9"
but when adding the @Gedmo\Translatable
annotation, when updating the schema it says:
The annotation "@Gedmo\Mapping\Annotation\Translatable" in property Modules\Blog\Entities\Post::$title does not exist, or could not be auto-loaded.`
Any hints on how to use the extensions would be very useful!
Thank you,
@nWidart I have the same issue, have you found the solution?
I've sadly not found a way to make it work.
In the mean time I've made a trait, a refactored version of @freekmurze, that handles the translations of an entity.
It basically lets you do something like the following:
$category = $this->entityManager->getRepository('Modules\Blog\Entities\Category')->find(1);
$post = new Post();
$post->createOrUpdateTranslation('title', 'en', 'Title en');
$post->createOrUpdateTranslation('title', 'fr', 'Titre fr');
$post->setCategory($category);
$this->entityManager->persist($post);
$this->entityManager->flush();
And to read a translation, simple access the property like usual:
$post->title
This solution isn't as clean as the Doctrine Extensions, but hopefully someone figures out how to use them inside Laravel with this package.
+1 to this, I think it needs a more flexible EM binding. Maybe pre- and post- EM created events to hook up extensions?
I got it working using: (In an own ServiceProvider)
$entityManager = $this->app['Doctrine\ORM\EntityManager'];
$eventManager = $entityManager->getEventManager();
$reader = $entityManager->getConfiguration()->getMetadataDriverImpl()->getReader();
DoctrineExtensions::registerAbstractMappingIntoDriverChainORM(
new MappingDriverChain(),
$reader
);
$sluggableListener = new SluggableListener();
$sluggableListener->setAnnotationReader($reader);
$eventManager->addEventSubscriber($sluggableListener);
$sortableListener = new SortableListener;
$sortableListener->setAnnotationReader($reader);
$eventManager->addEventSubscriber($sortableListener);
The code provided by @patrickbrouwers above works fine for the annotations but it does not create the database tables needed for some of the extensions such as Loggable and Translatable. The following code fixes this issue.
$entityManager = $this->app['Doctrine\ORM\EntityManager'];
$eventManager = $entityManager->getEventManager();
$reader = $entityManager->getConfiguration()->getMetadataDriverImpl()->getReader();
$driverChain = new MappingDriverChain();
DoctrineExtensions::registerMappingIntoDriverChainORM($driverChain, $reader);
$driverChain->addDriver($entityManager->getConfiguration()->getMetadataDriverImpl(), 'App');
$entityManager->getConfiguration()->setMetadataDriverImpl($driverChain);
$loggableListener = new LoggableListener();
$loggableListener->setAnnotationReader($reader);
$eventManager->addEventSubscriber($loggableListener);
Nice inprovement. Didn't try those onces yet.
In the meantime I have open-sourced my Laravel Doctrine solution, in which enabling DoctrineExtensions is as easy as adding the extension to the config file.
+1
Closing because project is no longer maintained. Thanks.
Hello,
Thanks for developing this package. It would be nice to add in support for Doctrine Extension into this package. I was thinking the main composer file would add in the Doctrine Extensions. But the configuration and inclusion would be set via this package's config file.
Example, in the file app/config/packages/mitchellvanw/laravel-doctrine/doctrine.php have a config array