I have a global function sanitizeName:
function sanitizeName($s) {
return preg_replace('/somethingCrazy/', 'notSoCrazy', $s);
}
I need to use it in entity (e.g. for RSS generation), in Twig's template and in controller.
If I write it as service or add as Twig function/filter I will not be able to access it in entity as it will be just wrong. Obviously I can copy it to entity, but it's also nasty solution. How do I do this properly?
You could write your own class with
static
method:Then, if you'd like, add a
Twig
filter/function which invokes thisstatic
method. This way, you have have access to it :Twig
template, via filter/functionHope this helps...