1
I am implementing in Symfony2 the behavior Blameable
using the Gedmo\Mapping\Annotation
. I have successfully implemented the Timestampable
, but I cannot implement the Blameable
. The problem is that I can’t get the user. I tried to rewrite the listener
that brings the Gedmo
, but he can’t access the user.
In relation to my config:
extension.listener:
class: Basepoint\SruBundle\Listener\DoctrineExtensionListener
calls:
- [ setContainer, [ @service_container ] ]
tags:
# translatable sets locale after router processing
- { name: kernel.event_listener, event: kernel.request, method: onLateKernelRequest, priority: -10 }
# loggable hooks user username if one is in security context
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
gedmo.listener.tree:
class: Gedmo\Tree\TreeListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
gedmo.listener.translatable:
class: Gedmo\Translatable\TranslatableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
- [ setDefaultLocale, [ %locale% ] ]
- [ setTranslationFallback, [ false ] ]
gedmo.listener.timestampable:
class: Gedmo\Timestampable\TimestampableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
gedmo.listener.sluggable:
class: Gedmo\Sluggable\SluggableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
gedmo.listener.sortable:
class: Gedmo\Sortable\SortableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
gedmo.listener.loggable:
class: Gedmo\Loggable\LoggableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
gedmo.listener.blameable:
class: Gedmo\Blameable\BlameableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
Class:
use Gedmo\Mapping\Annotation as Gedmo; // gedmo annotations
use Doctrine\ORM\Mapping as ORM;
// ...
/**
* @var string $createdBy
*
* @Gedmo\Blameable(on="create")
* @ORM\Column(type="string")
*/
private $createdBy;
/**
* @var string $updatedBy
*
* @Gedmo\Blameable(on="update")
* @ORM\Column(type="string")
*/
private $updatedBy;
// ...
The Timestampable
is working correctly.
What could be my problem?
Are you currently logged in with a user? From what I saw in the documentation, Doctrine itself already automatically tries to assign a user to the $createdBy and $updatedBy attributes, regardless of whether the attribute is a string or a reference.
– Rodrigo Rigotti