OroCRM Forums

Covering OroCRM topics, including community updates and company announcements.

Forums Forums OroCRM OroCRM – How do I? Questions How to edit an entity in a listener class?

This topic contains 4 replies, has 3 voices, and was last updated by  Andrey Yatsenko 4 years, 3 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #29610

    Adam
    Participant

    Hello,

    Can anyone give me an example of editing an entity in a listener class? Can I use doctrineHelper?

    • This topic was modified 4 years, 3 months ago by  Adam.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #29612

    Adam
    Participant

    Those don’t work:

    $entity = new Table();
    $entity->setId(1);
    $entity->setValue(‘TEST’);

    $entityManager->merge($entity);
    $entityManager->flush();

    #29613

    vsoroka
    Moderator
    #29614

    Adam
    Participant

    What if I don’t have OnFlushEventArgs $event class? Which class did I suppose to inject into my listener?

    #29615

    Andrey Yatsenko
    Moderator

    Hi Adam,
    To what event did you subscribe?
    It doesn’t matter what event you will chose, you’ll always have this “$event” in event listener, this can be different type, but anyway.

    If you want to flush on event listener – it’s better to subscribe to

    With first option you have possibility to work with UnitOfWork directly and it’s better for performance reasons.
    But most times second option will be easier to use as there you can flush directly without knowing how UnitOfWork works.

    It’s highly recommended to read this articles in order to understand doctrine event listeners
    https://symfony.com/doc/2.8/doctrine/event_listeners_subscribers.html
    https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/events.html

Viewing 4 replies - 1 through 4 (of 4 total)

The forum ‘OroCRM – How do I? Questions’ is closed to new topics and replies.

Back to top

You will be redirected to [title]. Would you like to continue?

Yes No

You will be redirected to [title]. Would you like to continue?

Yes No