@Saving event fires on wrong model

  • Hello everybody,

    I got two extensions - let call them:

    • foo/bar
    • foo/loremipsum

    Well - both extensions are namespaced and both are working fine, if the other extension is not installed. If both extensions are installed, there is something bad happening.

    Both extensions are using a model called Item.

    • foo/bar -> @Entity(tableClass="@foobar_item")
    • foo/loremipsum -> @Entity(tableClass="@loremipsum_item")

    Okay, that's not that cool - but this can happen, once there are many extensions out there.

    But now I got a problem... If I save an item in foo/bar, the @Saving event from foo/loremipsum is triggered and returns:

    1. Type error: Argument 2 passed to Foo\Loremipsum\Model\Item::saving() must be an instance of Foo\Loremipsum\Model\Item, instance of Foo\Bar\Model\Item given.

    Argh... The full source of this is:

    Alright... I can not change the naming itself... So how can I make sure the @Saving event is not being triggered by a model that has the same name?

  • I think I found a solution. When the entity is defined, it's possible to add an eventPrefix.


    1. /**
    2.  * @Entity(tableClass="@foobar_item", eventPrefix="foobar.item")
    3.  */

    This defines an event like this: