OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – Programming Questions override one controller from core bundle and keep /api/rest controllers

This topic contains 5 replies, has 2 voices, and was last updated by  Mike Kudelya 7 years, 4 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
  • #34278

    kroder
    Participant

    Good day.
    I’m trying to override couple of actions from OroEmailBundle/EmailController.
    No problems with common controllers through bundle inheritance, I redefined actions that I need and the rest of actions from EmailBundle/Controller/* are fine.
    The problem with controllers inside EmailBundle/Controller/Api/Rest/*, they all fall away no matter what I’m trying to write in routing.yml and routing_api.yml.
    Could anyone give me any advice or working example of these files to keep rest api controllers alive?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #34279

    Mike Kudelya
    Participant

    Hi

    Try to use this approach:

    Add to src/Custom/Bundle/OroBundle/Resources/config/oro/routing.yml:

    Add to src/Custom/Bundle/OroBundle/Resources/config/oro/routing_api.yml:

    and finally api controller src/Custom/Bundle/OroBundle/Controller/Api/Rest/EmailController.php:

    #34280

    kroder
    Participant

    Hi Mike, thanks for answer, I got all api routes available now.
    But new question appeared: is it normal, that some actions (actually all in OroEmailBundle\Controller except EmailController itself, EmailTemplateController as example) don’t have specified names in their @Route annotations? Because there are references from other code (‘oro_email_emailtemplate_index’ as example) which use generated action names, as I understand. So when I override bundle – these actions change their default names and I got ‘route not found’ exceptions. Should I inherit these controllers by myself and specify correct names for routes or it could be fixed in platform code?

    #34281

    Mike Kudelya
    Participant

    Hi

    Yes, by default @Route(name) is auto-generated. I think it is not normal, that route name is missed, it is historically happened.

    The best way to override business logic it is override service class name which this controller called, for example you can do this via Dependency Injection or event listener.

    But if you really want to override controller, you should do the following work. Unfortunately EmailTemplateController.php doesn’t contain any route name. You should copy it in your custom bundle and add route name to each action according to original auto-generated name (for example oro_email_emailtemplate_index). If you would have route names in controller, you will override only a few actions. Also you should create your routing.yml:

    #34282

    kroder
    Participant

    Thank you, Mike. Pretty clear now.
    Just in case: will it make any sense if I’ll create a pull request with route names in those two OroEmailBundle controllers?

    #34283

    Mike Kudelya
    Participant

    Hi

    It will be great!

    Thank you in advance!

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

The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.

Back to top