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 0a68737 commit e33f6c1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 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 1.4.19(Build 2024012400)
- Added a template and code to support it, that allows you to call a renderer function from a template

Version 1.4.18(Build 2022122200)
- will return an empty string for custom user profile fields that exist but are empty (previously returned the unparsed variable name)

Expand Down
16 changes: 16 additions & 0 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,22 @@ function filter_generico_callback(array $link) {
}
}

//If this is a renderer call, lets do it
//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['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);
$genericotemplate = str_replace('@@renderedcontent@@',$renderedcontent, $genericotemplate);
}

//If template requires a MOODLEPAGEID lets give them one
//this is legacy really. Now we have @@URLPARAM we could do it that way
$moodlepageid = optional_param('id', 0, PARAM_INT);
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,8 +25,8 @@

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

$plugin->version = 2022122200; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2024012400; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2011070100; // Requires this Moodle version
$plugin->component = 'filter_generico'; // Full name of the plugin (used for diagnostics)
$plugin->maturity = MATURITY_STABLE;
$plugin->release = 'Version 1.4.18(Build 2022122200)';
$plugin->release = 'Version 1.4.19(Build 2024012400)';

0 comments on commit e33f6c1

Please sign in to comment.