Is it possible to pass parameters with a hooksnippet call?
BigBlockStudios opened this issue · 2 comments
I have tried using the snippet with parameters as you normally would - does not work, so I also tried:
{ "aftersave": [{ "snippet": [{ "param1": "value1", "param2": "value2", etc..... }] }] }
but does not appear to work.
thing is the method already exists in my class (and requires parameters) and seems a little silly to duplicate it as a snippet.
Is is possible to pass parameters with the hooksnippet call?
you could create a new input field in your form with inputTVtype = 'hidden' and put the params as default value into that field, for example as json-string. Make sure, to set use Default if empty to 'yes'
Then, you can get that value with in your aftersave hooksnippet with
$scriptProperties['postvalues']['my_params']
when your hidden field has the name 'my_params'
Thanks - actually, I did something close to what you are suggesting. Since the "migx_after_save" snippet got passed $scriptProperties['scriptProperties'] & $scriptProperties['postvalues'] (which included which config was used)
I just wrote a multipurpose snippet that could call a method (or methods) based on the config and submitted data.
Since the params are 99% of the time in the input form, that got me where I was going :)