Skip to content

Commit

Permalink
Added a template and code to call a renderer function
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhunt committed Jan 24, 2024
1 parent 87ed729 commit e848abc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Change List
=========
Version 3.1.72(Build 2024012400)
- Added a template and code to support it, that allows you to call a renderer function from a template

Version 3.1.71(2023101300)
- removed debugger statement
- removed deprecated calback call which php8.2 complained about
Expand Down
14 changes: 11 additions & 3 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,18 @@ function filter_poodll_process(array $link, $ext = false) {
}

//If this is a renderer call, lets do it
if(isset($filterprops['component']) && isset($filterprops['function']) && isset($filterprops['cmid'])){
//it will be a function in a renderer with a name that begins with "embed_" .. e.g "embed_something"
//the args filterprops will be a pipe delimited string of args, eg {POODLL:type="mod_ogte",function="embed_table",args="arg1|arg2|arg3"}
//if the args string contains "cloudpoodlltoken" it will be replaced with the actual cloud poodll token.
if(isset($filterprops['renderer']) && isset($filterprops['function']) && strpos($filterprops['function'],'embed_')===0){
if(!isset($token)){$token=false;}
$somerenderer = $PAGE->get_renderer($filterprops['component']);
$renderedcontent=call_user_func_array([$somerenderer, $filterprops['function']], [$filterprops['cmid'],$token]);
$somerenderer = $PAGE->get_renderer($filterprops['renderer']);
$args=[];
if(isset($filterprops['args'])){
$args_string =str_replace('cloudpoodlltoken',$token,$filterprops['args']);
$args_array = explode('|',$args_string);
}
$renderedcontent=call_user_func_array([$somerenderer, $filterprops['function']], $args_array);
$poodlltemplate = str_replace('@@renderedcontent@@',$renderedcontent, $poodlltemplate);
}

Expand Down
1 change: 1 addition & 0 deletions presets/renderedcontent.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"Rendered Content","key":"renderedcontent","version":"1.0.1","instructions":"This will fetch and display from a Moodle renderer given the renderer/component name, function name and pipe delimited set of arguments to the function.","showatto":"0","showplayers":"0","requirecss":"","requirejs":"","shim":"","defaults":"renderer=\"\",function=\"\",args=\"\"","amd":"1","body":"<!-- @@CLOUDPOODLLTOKEN@@ @@renderer@@ @@function@@ @@args@@ -->\n@@renderedcontent@@","bodyend":"","script":"","style":"","dataset":"","datasetvars":"","alternate":"","alternateend":""}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023101300;
$plugin->version = 2024012400;
$plugin->requires = 2016052300;//moodle 3.1.0
$plugin->component = 'filter_poodll';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '3.1.71(Build 2023101300)';
$plugin->release = '3.1.72(Build 2024012400)';

0 comments on commit e848abc

Please sign in to comment.