Created
October 17, 2016 18:58
-
-
Save Padam87/835a7025635d5ebc712421a50eec89d7 to your computer and use it in GitHub Desktop.
Sonata list route type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends admin.getTemplate('base_list_field') %} | |
{% block field %} | |
{% set parameters = {} %} | |
{% for name, value in field_description.options.parameters %} | |
{% set parameters = parameters|merge({ (name): call_user_func(value, object) }) %} | |
{% endfor %} | |
<a {% for name, value in field_description.options.a.attributes %}{{ name }}="{{ value }}" {% endfor %} | |
href="{{ path(call_user_func(field_description.options.name, object), parameters) }}" > | |
{{ call_user_func(field_description.options.a.html, object)|raw }} | |
</a> | |
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class PhpFunctionExtension extends \Twig_Extension | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getFunctions() | |
{ | |
return [ | |
new \Twig_SimpleFunction('call_user_func', 'call_user_func'), | |
new \Twig_SimpleFunction('call_user_func_array', 'call_user_func_array'), | |
]; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getName() | |
{ | |
return 'phpfunc'; | |
} | |
} |
Using Symfony 4.3, how can I tell Sonata to use the custom template? I only get an error that the (original) template doesn't understand this syntax ("Catchable Fatal Error: Object of class Closure could not be converted to string") and the list_url
template is not listed here as overridable: https://symfony.com/doc/master/bundles/SonataAdminBundle/reference/templates.html#configuring-templates
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use this instead of the extension: https://github.com/umpirsky/twig-php-function
Usage