DoctrineExtensions: Sortable doesn't work according to the documentation

I’ve tried this example in my application (copy-paste) and it doesn’t print what it’s supposed to.

Expected output (according to docs):

0: item 0
1: item 1
2: item 2

Actual output:

0: item 1
0: item 0
1: item 2

Version: Gedmo 2.3.9 + Doctrine 2.4.4

Is something missing in the docs or is it a bug?

About this issue

  • Original URL
  • State: open
  • Created 10 years ago
  • Comments: 16 (3 by maintainers)

Most upvoted comments

I had the same problem. The SortableListener was registered twice but has to run only once.

Could you advise on how to do so please ?

I just get all listeners of event “onFlush” and look for the existence of SortableListener.

$listeners = array_map(
    static fn($listener) => get_class($listener),
    $em->getEventManager()->getListeners('onFlush')
);
if ( ! in_array(SortableListener::class, $listeners, true)) {
    $em->getEventManager()->addEventSubscriber(new SortableListener());
}