So i'm trying to extend the SonataAdmin show view to have a list of the document's versions (phpcr checkpoint or checkin).
I've got the list of saved versions showing correctly, and now i need to make them into links that display that version of the content, but i'm getting the following error when trying to add a custom Route:
An exception has been thrown during the rendering of a template
("Parameter "id" for route "admin_cmsbundle_product_show_version" must
match "[^/]++" ("mstr/product/product-253562" given) to generate a
corresponding URL.") in CmsBundle:product:show.html.twig at line 18.
This is my configureRoutes in my admin class:
protected function configureRoutes(RouteCollection $collection)
{
$collection->add('show_version', $this->getRouterIdParameter() . '/show/{version}');
}
This is my overriden template:
{% block show %}
<ul>
{% for version in versions %}
<li><a href="{{ admin.generateObjectUrl('show_version', object, {'version': version.name}) }}">Version: {{ version.name }} </a></li>
{% endfor %}
</ul>
{{ parent() }}
{% endblock %}
This is my edited show action (to include the versions list):
public function showAction($id = null)
{
...
return $this->render($this->admin->getTemplate('show'), array(
'action' => 'show',
'object' => $object,
'elements' => $this->admin->getShow(),
'versions' => $this->getVersionHistory($object)
));
}
And this is my showVersion action in the controller:
public function showVersionAction($id = null, $version = "1.0")
{
...
return $this->render($this->admin->getTemplate('show'), array(
'action' => 'show',
'object' => $this->getVersion($object, $version),
'elements' => $this->admin->getShow(),
'versions' => $this->getVersionHistory($object)
));
}
Note, generateUrl gives the same error:
<a href="{{ admin.generateUrl('show_version', {'id': object.id, 'version': version.name}) }}">Version: {{ version.name }} </a>
What am i doing wrong?
Any help on fixing this would be greatly appreciated :)
Bit of digging around and the answer was simple, just had to override the pattern for id to be .+