Last active
April 29, 2022 07:31
-
-
Save martinlipp/c78e58be20672edda3fe5fefaaa2edb2 to your computer and use it in GitHub Desktop.
Add custom Doctrine query hints in Neos Flow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\Demo\Persistence\Doctrine; | |
use Doctrine\DBAL\DBALException; | |
use Doctrine\ORM\Configuration; | |
use Doctrine\ORM\EntityManager; | |
use Doctrine\ORM\Query; | |
use Gedmo\Translatable\Query\TreeWalker\TranslationWalker; | |
use Gedmo\Translatable\TranslatableListener; | |
/** | |
* @Flow\Scope("singleton") | |
*/ | |
class EntityManagerConfiguration | |
{ | |
/** | |
* Enhance the Doctrine EntityManager by applying post creation settings, like custom filters. | |
* | |
* @param Configuration $config | |
* @param EntityManager $entityManager | |
* @throws DBALException | |
*/ | |
public function enhanceEntityManager(Configuration $config, EntityManager $entityManager): void | |
{ | |
// Check sandstorm/gedmotranslatableconnector for setting up Gedmo Translatable in Neos Flow (https://github.com/sandstorm/GedmoTranslatableConnector) | |
$config->setDefaultQueryHint(Query::HINT_CUSTOM_OUTPUT_WALKER, TranslationWalker::class); | |
$config->setDefaultQueryHint(TranslatableListener::HINT_TRANSLATABLE_LOCALE, 'en'); | |
$config->setDefaultQueryHint(TranslatableListener::HINT_FALLBACK, 1); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\Demo; | |
use Doctrine\ORM\Mapping\Driver\AnnotationDriver; | |
use Neos\Flow\Persistence\Doctrine\EntityManagerFactory; | |
/** | |
* @package Acme\Demo | |
*/ | |
class Package extends \Neos\Flow\Package\Package | |
{ | |
public function boot(\Neos\Flow\Core\Bootstrap $bootstrap) | |
{ | |
$bootstrap->getSignalSlotDispatcher()->connect(EntityManagerFactory::class, 'afterDoctrineEntityManagerCreation', \Acme\Demo\Persistence\Doctrine\EntityManagerConfiguration::class, 'enhanceEntityManager'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment