Overriding ResourceController:createAction, resource has not been found

Hi!
I’m trying to override the ResourceController for my Option entity.
First, I just want to write my own createAction.

I created my controller (src/Controller/Licence/OptionController.php):

<?php

namespace App\Controller\Licence;

use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sylius\Component\Resource\ResourceActions;
use FOS\RestBundle\View\View;
class OptionController extends ResourceController
{
    public function createAction(Request $request): Response
    {
      //My method
    }
}

I have defined my resource (config/package/sylius_resource.yaml):

sylius_resource:
  resources:
    app.option:
      driver: doctrine/orm
        classes:
          model: App\Entity\LicenceOption\Option
          form: App\Form\Type\LicenceOptionFormType
          controller: App\Controller\Licence\OptionController

Declared my service (config/services.yaml):

services:
  App\Controller\Licence\OptionController:
    autowire: false
    public: true

And my route (config/routes.yaml):

app_admin_option_create:
  path: /admin/options/new
  methods: [POST, GET]
  defaults:
    _controller: app.controller.option:createAction

But on the creation form view (OptionController:createAction, method GET), I get this error:
The "option" has not been found

Thanks for your help :slight_smile:

I finally find the solution. In my configuration, I was declaring my app_admin_option_create AFTER all the Option routes.

To fix this, I have declared my creation route BEFORE the other routes:

app_admin_option_create:
path: /admin/options/new
methods: [GET, POST]
defaults:
    _controller: app.controller.option:createAction

app_admin_option:
    prefix: /admin
   resource: |
        alias: app.option
        section: admin
        templates: SyliusAdminBundle:Crud
        grid: app_admin_option
        redirect: index
        vars:
            all:
                subheader: app.ui.option
                templates:
                    form: "@SyliusAdmin/Option/_form.html.twig"
            index:
                icon: 'clipboard list'
    type: sylius.resource