Skip to content

#[MapEntity] and render controller from twig #52875

Closed
@onEXHovia

Description

@onEXHovia

Symfony version(s) affected

6.4

Description

When updating project and replacing ParamConverter to MapEntity, when render controller from a template, it fails.
Exception example:

An exception has been thrown during the rendering of a template ("Controller "App\Controller\ListController" requires that you provide a value for the "$tag" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or there is a non-optional argument after this one.").

When used ParamConverter two options worked: calling via http and via render(controller()), now only http.

How to reproduce

Below there will be a simplified example, the controller is available by route and we want to call it in the template with a pre-selected entity.

Controller:

<?php

namespace App\Controller;

use App\Entity\Tag;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

final class ListController
{
    #[Route('/list/{slug}', name: 'app_list', methods: ['GET'])]
    public function __invoke(Request $request, #[MapEntity] Tag $tag): Response
    {
        return new Response($tag->getId());
    }
}

Template:

{{ render(controller('App\\Controller\\ListController', {
    'tag': tag,
})) }}

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions