Permalink
Browse files

MDL-33640 - Add ability to use custom filepicker templates

Allow repository plugins to register a template by defining a get_template() method, coupled with the ability to request the template be used by create_upload_form() instead of the standard 'uploadform' template.  The template is automatically registered using the plugin's name, and core templates will override any which clash; this also means that a theme can override these templates in a custom renderer if it wants to.
  • Loading branch information...
1 parent 470d47f commit 013cf2878c000459b2a1fe8dcbb482b35a723e2b @pauln pauln committed Aug 8, 2012
Showing with 8 additions and 2 deletions.
  1. +2 −1 repository/filepicker.js
  2. +6 −1 repository/lib.php
View
3 repository/filepicker.js
@@ -1618,7 +1618,8 @@ M.core_filepicker.init = function(Y, options) {
var client_id = this.options.client_id;
var id = data.upload.id+'_'+client_id;
var content = this.fpnode.one('.fp-content');
- content.setContent(M.core_filepicker.templates.uploadform);
+ var template = data.template || 'uploadform';
+ content.setContent(M.core_filepicker.templates[template]);
content.all('.fp-file,.fp-saveas,.fp-setauthor,.fp-setlicense').each(function (node) {
node.all('label').set('for', node.one('input,select').generateID());
View
7 repository/lib.php
@@ -2684,16 +2684,21 @@ function initialise_filepicker($args) {
// provided by form element
$return->accepted_types = file_get_typegroup('extension', $args->accepted_types);
$return->return_types = $args->return_types;
+ $templates = array();
foreach ($repositories as $repository) {
$meta = $repository->get_meta();
// Please note that the array keys for repositories are used within
// JavaScript a lot, the key NEEDS to be the repository id.
$return->repositories[$repository->id] = $meta;
+ // Register custom repository template if it has one
+ if(method_exists($repository, 'get_template')) {
+ $templates[$meta->type] = $repository->get_template();
+ }
}
if (!$templatesinitialized) {
// we need to send filepicker templates to the browser just once
$fprenderer = $PAGE->get_renderer('core', 'files');
- $templates = $fprenderer->filepicker_js_templates();
+ $templates = array_merge($templates, $fprenderer->filepicker_js_templates());
$PAGE->requires->js_init_call('M.core_filepicker.set_templates', array($templates), true);
$templatesinitialized = true;
}

0 comments on commit 013cf28

Please sign in to comment.