rsanchez / json

Output ExpressionEngine data in JSON format.
http://devot-ee.com/add-ons/json/
100 stars 236 forks source link

collect response options earlier for EE 2.5.5 #60

Closed ahebrank closed 5 years ago

ahebrank commented 7 years ago

I'm not sure why I had to do this, but with an old EE 2.5.5 site, these response option template parameters were ignored until I did this to grab them earlier -- presumably it's irrelevant for newer installs sharing in case it helps anyone.

domstubbs commented 6 years ago

I’ve just started to work on an export workflow for an old EE2 site and I’ve noticed the same thing. It looks as though there’s an issue with the Json_Template class overriding ee()->TMPL in its constructor and then failing to restore the original object in its destructor. It does try to restore it but for some reason that’s not working reliably.

It looks as though this class is only instantiated in one place, so a simple workaround is to replicate the intended constructor/destructor behaviour in the main plugin. This seems to work reliably.

$ee_tmpl = ee()->TMPL;
$template = new Json_Template();

$field_data = ee()->api_channel_fields->apply('replace_tag', array($field_data, array(), $tagdata));

if ($template->variables)
{
    $field_data = $template->variables;
}

unset($template);
ee()->TMPL = $ee_tmpl;

I noticed a couple of other Github issues where people report params being ignored and my guess is this is at the root of all of them.

ahebrank commented 5 years ago

Closing out -- haven't tested (can't remember which site I had this issue with), but the note above makes sense.