Search code examples
symfonysylius

Sylius: route params missing on redirect (SyliusResourceBundle)


I have a nested administration that shows version of parent-objects, and I have to pass the route-parameter from the parent to the version management. The following config works fine, but I get the error, that a required route parameter is missing after editing and deleting a version:

Some mandatory parameters are missing ("parentCode") to generate a URL for route "...".

The routing config looks like this:

app.admin.parent_version:
    resource: |
        alias: app.parent_version
        path: "admin/parents/{parentCode}/versions"
        section: admin
        templates: "@SyliusAdmin\\Crud"
        except: ['show']
        redirect: update
        grid: app.admin.parent_version
        permission: true
        vars:
            route:
                parameters:
                    parentCode: $parentCode
            all:
                templates:
                    form: "/Admin/ParentVersion/_form.html.twig"
                    breadcrumb: "/Admin/ParentVersion/_breadcrumb.html.twig"
            index:
                parameters:
                    parentCode: $parentCode
            create:
                route:
                    parameters:
                        parentCode: $parentCode
            update:
                route:
                    parameters:
                        parentCode: $parentCode
                        id: resource.id
    type: sylius.resource

The key 'config' is a scalar, but in vendor/sylius/resource-bundle/src/Bundle/Controller/RequestConfiguration::getRedirectParameters it seems, that i can configure parameters like in the vars-key above:

  $redirect = $this->parameters->get('redirect');
        if (isset($redirect['parameters']) && $redirect['parameters'] === []) {
            return [];
        }

        if (!is_array($redirect)) {
            $redirect = ['parameters' => []];
        }

        $parameters = $redirect['parameters'] ?? [];
        $parameters = $this->addExtraRedirectParameters($parameters);

        if (null !== $resource) {
            $parameters = $this->parseResourceValues($parameters, $resource);
        }

If I dump $ $parameters, there is just the id of the created/deleted/updated object. The docs for the routing would suggeste this too (https://github.com/Sylius/SyliusResourceBundle/blob/master/docs/create_resource.md#custom-redirect-after-success) but as said, this is a scalar-field in the config.

Does anyone know, how I can get rid of this error?


Solution

  • Do you mean to redirect from update to update route? I would suppose it could work like this example:

    vars:
    update:
        redirect:
            route: update
            parameters:
                parentCode: $parentCode
                id: resource.id
    

    Also, could you try to define update route manually? Like this

    app.admin.parent_version_update:
    path: /update
    controller: app.controller.parent_version::updateAction
    _defaults:
        _sylius:
            section: admin
            templates: "@SyliusAdmin\\Crud\\update.html.twig"
            redirect:
                route: app.admin.parent_version_index
                parameters:
                    parentCode: $parentCode
                    id: resource.id