Comments (10)
your custom listener has to extend the Gedmo one to pass the typehint
from stofdoctrineextensionsbundle.
Overriding the listener class through the configuration works for me. Could you provide more details to allow me to reproduce your issue ?
from stofdoctrineextensionsbundle.
My ORM listener looks exactly like yours, it's in my own Bundle, and all I've done is change the session variable that it listens for. My listener extends yours and overrides your method. Is there anything else I need to do to get the listener to maybe register with Symfony?
namespace MRX\Common\MrxCoreBundle\ORM;
use Stof\DoctrineExtensionsBundle\ORM\TranslationListener as BaseTranslationListener;
use Symfony\Component\HttpFoundation\Session;
class TranslationListener extends BaseTranslationListener
{
/**
* Set the translation listener locale from the session.
*
* @param Session $session
* @return void
*/
public function setTranslatableLocaleFromSession(Session $session = null)
{
if ($session !== null) {
if( $locale = $session->get('entity.locale') ){
//override default locale when grabbing entity
$this->setTranslatableLocale( $locale );
}else{
//Otherwise go for session locale
parent::setTranslatableLocaleFromSession( $session );
}
}
}
}
from stofdoctrineextensionsbundle.
Note sure why the code block isn't working for me properly, but you get the idea.
from stofdoctrineextensionsbundle.
The class itself has nothing to do with the configuration. (The listener will fail if it is incorrect but this is another issue). I even tried with a non-existent class and checked the dumped container.
Could you provide your entire configuration file to check if the issue is in it ?
from stofdoctrineextensionsbundle.
I've got the same problem than @justfortier with loggable.
stof_doctrine_extensions:
default_locale: fr_FR
orm:
default:
loggable: true
translatable: false
class:
loggable: Acme\Bundle\DemoBundle\Listener\LoggableListener
But container returns an error :
Catchable Fatal Error: Argument 1 passed to Stof\DoctrineExtensionsBundle\EventListener\LoggerListener::__construct() must be an instance of Gedmo\Loggable\LoggableListener, instance of Acme\Bundle\DemoBundle\Listener\LoggableListener given,
I use sf 2.1.
from stofdoctrineextensionsbundle.
Ok thanks a lot
from stofdoctrineextensionsbundle.
How should I do if my custom listener needs some additional constructor argument?
I want to log user_id instead of username, so I tried to inject @security.token_storage
into my listener and extract user from there. But that leads to error during container compile:
Too few arguments to function App\EventSubscriber\LoggableListener::__construct(), 0 passed in /var/www/app/var/cache/dev/ContainerQeDNUly/srcApp_KernelDevDebugContainer.php on line 2259 and exactly 1 expected
I've tried to override whole stof_doctrine_extensions.listener.loggable
service and seems container was built, but now methods of base listener are not called anymore (prePersistLogEntry
, onFlush
and so on).
UPD: Just realized that $username
is really Token, so I able to extract user from there. But question about additional constructor argument is still interesting for me.
from stofdoctrineextensionsbundle.
@VBelozyorov did you manage to fix this error?
UPD: I've added custom argument (method call in fact, it was repository so as argument it resulted in endless loop) using compiler pass in kernel class.
from stofdoctrineextensionsbundle.
Hi, anyone found a way to pass extra arguments to a custom listener please ?
I'm currently struggling with this since I try to override the prePersistLogEntry method in order to set properties on my CustomLogEntry entity, I would like to log the user firstname, lastname and ID aswell :'(
Thanks for your help
from stofdoctrineextensionsbundle.
Related Issues (20)
- Argument 1 passed to Gedmo\Mapping\MappedEventSubscriber::loadMetadataForObjectClass
- ext_translations table not generated HOT 1
- Support php 8.0 HOT 9
- php8 compatibility HOT 2
- Integrity constraint violation HOT 1
- PHP Fatal error: Uncaught Error: Class 'Doctrine\Bundle\DoctrineExtensionsBundle\DoctrineExtensionsBundle' not found in /home/mciat/Software/api-yelo.eco/src/Kernel.php:25 HOT 1
- Undefined constant Doctrine\DBAL\Types\Type::<Insert constant coin here> HOT 2
- SoftDeleted entities are not filtered/excluded from database results HOT 1
- loggable and doctrine migrations
- [SoftDeletable] How to disable on entity getter HOT 2
- Sort error when using Repository functions HOT 1
- Next release ? HOT 4
- doctrine.event_subscriber is deprecated HOT 3
- Timestampable logic no longer works on 1.8.0 HOT 6
- Listeners not working HOT 3
- UnexpectedValueException: tree metadata HOT 7
- Allow the bundle to work without the annotation reader HOT 3
- Support Symfony 7, Switch doctrine suubscribers to #[AsDoctrineListener] HOT 1
- Support Symfony 7 HOT 3
- [TimeStampable] symfony/clock use instead of new DateTime HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stofdoctrineextensionsbundle.