According to How to use Doctrine Entity Listener with Symfony 2.4? it should be pretty simple to setup the entity listener feature in Symfony.
Unfortunately, my listener nevers gets called and I don't know why. I've checked the compiler pass of the doctrine bundle and also the DefaultEntityListenerResolver class. My listener is gets passed to the register method and should be available then. The resolve method on the other hand seems to be never called.
Here is my service definition:
insite.entity.listener.page_node:
class: NutCase\InSiteBundle\Entity\PageNodeListener
tags:
- { name: doctrine.orm.entity_listener }
Here is my listener:
namespace NutCase\InSiteBundle\Entity;
use Doctrine\ORM\Event\LifecycleEventArgs;
class PageNodeListener
{
public function prePersist( PageNode $node, LifecycleEventArgs $event )
{
die("okay");
}
}
And here my yaml for the entity:
NutCase\InSiteBundle\Entity\PageNode:
type: entity
table: page_node
repositoryClass: NutCase\InSiteBundle\Entity\PageNodeRepository
fields:
title:
type: string
length: 255
nullable: false
segment:
type: string
length: 255
nullable: false
url:
type: string
length: 255
nullable: false
root:
type: boolean
nullable: false
hidden:
type: boolean
nullable: false
I've added an "entityListeners" entry to the YAML, since I thought this one is missing:
entityListeners:
- PageNodeListener // Also tried the full namespace
Which only leads to the following error whenever I try to load a PageNode entity:
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: Invalid argument supplied for foreach()
Any suggestions?