Another way would be to override the method generateObjectUrl()
in your object's admin class.
/**
* @see \Sonata\AdminBundle\Admin\Admin::generateObjectUrl()
*/
public function generateObjectUrl($name, $object, array $parameters = array(), $absolute = false)
{
if ('show' == $name) {
return $this->getRouteGenerator()->generate('your_route_to_public_facing_view', [
'id' => $this->getUrlsafeIdentifier($object),
], $absolute );
}
$parameters['id'] = $this->getUrlsafeIdentifier($object);
return $this->generateUrl($name, $parameters, $absolute);
}
And that's it. No mucking with templates. And no template code that will run on every other admin.
To get the link to appear automatically, you will have to add something to the $showMapper
via configureShowFields()
. (If anyone knows a better way, please do tell.)
Overriding generateObjectUrl()
has another bonus: If you display a show
button on the $listMapper
, the URL there will be updated there as well.
Edited to say: since this overrides the show
route, you will no longer be able to use that built-in feature. That's ok for me since I need to view my object with all the front-end css and js loaded.