Skip to content

Commit

Permalink
Dev: added json_decode function to twig
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Dec 12, 2017
1 parent 59ad743 commit f47dc47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions application/config/internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,11 @@
'str_replace' => 'str_replace',
'assetPublish' => 'LS_Twig_Extension::assetPublish',
'image' => 'LS_Twig_Extension::image',
'imageSrc' => 'LS_Twig_Extension::imageSrc',
'imageSrc' => 'LS_Twig_Extension::imageSrc',
'sprintf' => 'sprintf',
'gT' => 'gT',
'createUrl' => 'LS_Twig_Extension::createUrl',
'json_decode' => 'LS_Twig_Extension::json_decode',
),
'filters' => array(
'jencode' => 'CJSON::encode',
Expand All @@ -263,7 +264,7 @@
'Question' => array('qid', 'parent_qid', 'sid', 'gid', 'type', 'title', 'question', 'help', 'other', 'mandatory', 'language', 'scale_qid'),
'QuestionGroups' => array('gid', 'sid', 'group_name', 'group_order', 'description', 'language', 'randomization_group', 'grelevance')
),
'functions' => array('include', 'dump', 'flatEllipsizeText', 'getLanguageData', 'array_flip', 'array_intersect_key', 'registerPublicCssFile', 'registerTemplateCssFile', 'registerGeneralScript', 'registerTemplateScript', 'registerScript', 'registerPackage', 'unregisterPackage', 'unregisterScriptFile', 'unregisterScriptForAjax', 'listCoreScripts', 'listScriptFiles', 'getAllQuestionClasses', 'intval', 'count', 'empty', 'reset', 'renderCaptcha', 'getPost', 'getParam', 'getQuery', 'isset', 'str_replace', 'assetPublish', 'image', 'imageSrc', 'sprintf', 'gT', 'createUrl'),
'functions' => array('include', 'dump', 'flatEllipsizeText', 'getLanguageData', 'array_flip', 'array_intersect_key', 'registerPublicCssFile', 'registerTemplateCssFile', 'registerGeneralScript', 'registerTemplateScript', 'registerScript', 'registerPackage', 'unregisterPackage', 'unregisterScriptFile', 'unregisterScriptForAjax', 'listCoreScripts', 'listScriptFiles', 'getAllQuestionClasses', 'intval', 'count', 'empty', 'reset', 'renderCaptcha', 'getPost', 'getParam', 'getQuery', 'isset', 'str_replace', 'assetPublish', 'image', 'imageSrc', 'sprintf', 'gT', 'createUrl', json_decode),
),

),
Expand Down
8 changes: 8 additions & 0 deletions application/core/LS_Twig_Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ public static function registerScript($id, $script, $position = null, array $htm
);
}

/**
* Convert a json object to a PHP array (so no troubles with object method in sandbox)
*/
public static function json_decode($json)
{
return (array) json_decode($json);
}

/**
* @param $position
* @return string
Expand Down

0 comments on commit f47dc47

Please sign in to comment.