sensio/SensioFrameworkExtraBundle — Issue #80: DoctrineParamConverter with twig {% render ... %} tag
Author: Problematic
Created: 2011-12-13 01:03:26+00:00
State: open

In several places in my views, I have an entity that I'm displaying by doing something similar to this:

{% render 'FooBarBundle:Baz:view' with {'entity': entity} %}

Up until today, I seem to recall this working just fine. However, today I updated my vendors (for the first time in a while, I suppose), and the param converter is incorrectly trying to convert `entity` to a Doctrine instance (the controller action is typehinted for the entity class), even though it already is one, and is throwing the `\LogicException` "Unable to guess how to get a Doctrine instance..."

Is this behavior a regression that I introduced in my own code, or did something change in the param converter and/or Doctrine lately that would cause this? It seems like a waste to pull out an id and let Doctrine fetch the entity again when I already have a perfectly good instance.

For what it's worth, the following block in the `apply()` method of the param converter (I couldn't find a way to do it in `supports()`, sorry) seems to fix the issue without breaking anything else:

if ($request->attributes->get($configuration->getName()) instanceof $class) {
return;
}

If this is a valid solution, I'd be happy to open a pull request; if I'm misusing the twig `render` tag, I guess I'd like to know that as well.