Commit 6970f052 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Move blockconfig filebrowser element definition into file base class

parent fcfe1914
......@@ -148,7 +148,7 @@ class PluginBlocktypeFiledownload extends PluginBlocktype {
return ArtefactTypeFileBase::artefactchooser_get_file_data($artefact);
}
public static function filebrowser_element(&$instance, $default=null, $istemplate=false) {
public static function filebrowser_element(&$instance, $default=array(), $istemplate=false) {
$element = array(
'name' => 'filebrowser',
'type' => 'filebrowser',
......@@ -168,7 +168,7 @@ class PluginBlocktypeFiledownload extends PluginBlocktype {
),
'selectlistcallback' => array(
'name' => 'artefact_get_records_by_id',
'args' => array(empty($default) ? array() : $default),
'args' => array($default),
),
);
if (!$istemplate) {
......
......@@ -67,7 +67,7 @@ class PluginBlocktypeHtml extends PluginBlocktype {
safe_require('artefact', 'file');
$instance->set('artefactplugin', 'file');
return array(
'filebrowser' => self::filebrowser_element($instance, (isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $istemplate),
'filebrowser' => self::filebrowser_element($instance, (isset($configdata['artefactid'])) ? array($configdata['artefactid']) : null, $istemplate),
);
}
......@@ -87,41 +87,14 @@ class PluginBlocktypeHtml extends PluginBlocktype {
return $mimetypes;
}
public static function filebrowser_element(&$instance, $default=null, $istemplate=false) {
$element = array(
'name' => 'filebrowser',
'type' => 'filebrowser',
'title' => get_string('file', 'artefact.file'),
'folder' => (int) param_variable('folder', 0),
'highlight' => null,
'browse' => true,
'page' => View::make_base_url(),
'config' => array(
'upload' => true,
'uploadagreement' => get_config_plugin('artefact', 'file', 'uploadagreement'),
'createfolder' => false,
'edit' => false,
'select' => true,
'selectone' => true,
'alwaysopen' => true,
),
'tabs' => $instance->get_view()->ownership(),
'filters' => array(
'artefacttype' => array('file'),
'filetype' => self::get_allowed_mimetypes(),
),
'selectlistcallback' => array(
'name' => 'artefact_get_records_by_id',
'args' => array(empty($default) ? array() : array($default)),
),
public static function filebrowser_element(&$instance, $default=array(), $istemplate=false) {
$element = ArtefactTypeFileBase::blockconfig_filebrowser_element($instance, $default, $istemplate);
$element['title'] = get_string('file', 'artefact.file');
$element['config']['selectone'] = true;
$element['filters'] = array(
'artefacttype' => array('file'),
'filetype' => self::get_allowed_mimetypes(),
);
if (!$istemplate) {
// You don't have to choose a file if this view is a template
$element['rules'] = array(
'required' => true,
);
}
return $element;
}
......
......@@ -743,6 +743,39 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
}
return $newname;
}
public static function blockconfig_filebrowser_element(&$instance, $default=array(), $istemplate=false) {
$element = array(
'name' => 'filebrowser',
'type' => 'filebrowser',
'title' => get_string('file', 'artefact.file'),
'folder' => (int) param_variable('folder', 0),
'highlight' => null,
'browse' => true,
'page' => View::make_base_url(),
'config' => array(
'upload' => true,
'uploadagreement' => get_config_plugin('artefact', 'file', 'uploadagreement'),
'createfolder' => false,
'edit' => false,
'select' => true,
'alwaysopen' => true,
),
'tabs' => $instance->get_view()->ownership(),
'selectlistcallback' => array(
'name' => 'artefact_get_records_by_id',
'args' => array($default),
),
);
if (!$istemplate) {
// You don't have to choose a file if this view is a template
$element['rules'] = array(
'required' => true,
);
}
return $element;
}
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment