its a bit of a mind-bender, yes. recursion + events can be fun :-)

my proposal would be to raise the event *before* the item is even created, to give the event handler the oportunity to create the item however it wants to (that then also supports creating an item from a node that would not be supported by our factory). if the event says to not have an item at all, we return null immediately, just as previously with the second line if(empty($item)). if the event simply did not get set an item, we create it and check if the event got told not to loop over the children.