Coder Social home page Coder Social logo

Comments (10)

stof avatar stof commented on May 28, 2024 1

your custom listener has to extend the Gedmo one to pass the typehint

from stofdoctrineextensionsbundle.

stof avatar stof commented on May 28, 2024

Overriding the listener class through the configuration works for me. Could you provide more details to allow me to reproduce your issue ?

from stofdoctrineextensionsbundle.

justfortier avatar justfortier commented on May 28, 2024

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.

justfortier avatar justfortier commented on May 28, 2024

Note sure why the code block isn't working for me properly, but you get the idea.

from stofdoctrineextensionsbundle.

stof avatar stof commented on May 28, 2024

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.

ehibes avatar ehibes commented on May 28, 2024

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.

ehibes avatar ehibes commented on May 28, 2024

Ok thanks a lot

from stofdoctrineextensionsbundle.

VBelozyorov avatar VBelozyorov commented on May 28, 2024

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.

mleczakm avatar mleczakm commented on May 28, 2024

@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.

coderpauloo avatar coderpauloo commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.