Commit accf258a authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

Fixed plugin config (now plays nice with new Pieform API)

parent fdb99411
......@@ -50,13 +50,10 @@ if (!call_static_method($classname, 'has_config')) {
$form = call_static_method($classname, 'get_config_options');
if (isset($form['submitfunction'])) {
$submitfunction = $form['submitfunction'];
}
if (isset($form['validatefunction'])) {
$validatefunction = $form['validatefunction'];
}
$form['plugintype'] = $plugintype;
$form['pluginname'] = $pluginname;
$form['name'] = 'pluginconfig';
$form['pluginconfigform'] = true;
$form['jsform'] = true;
$form['successcallback'] = 'pluginconfig_submit';
$form['validatecallback'] = 'pluginconfig_validate';
......@@ -72,6 +69,10 @@ $form['elements']['type'] = array(
'type' => 'hidden',
'value' => $type
);
$form['elements']['save'] = array(
'type' => 'submit',
'value' => get_string('save'),
);
$smarty = smarty();
$smarty->assign('form', pieform($form));
......@@ -83,18 +84,14 @@ $smarty->display('admin/extensions/pluginconfig.tpl');
function pluginconfig_submit(Pieform $form, $values) {
$success = false;
global $submitfunction, $plugintype, $pluginname, $classname;
if (!empty($submitfunction)) {
try {
call_static_method($classname, $submitfunction, $values);
$success = true;
}
catch (Exception $e) {
$success = false;
}
global $plugintype, $pluginname, $classname;
try {
call_static_method($classname, 'save_config_options', $values);
$success = true;
}
else {
// call set_plugin_config and stuffs
catch (Exception $e) {
$success = false;
}
if ($success) {
......@@ -106,9 +103,10 @@ function pluginconfig_submit(Pieform $form, $values) {
}
function pluginconfig_validate(PieForm $form, $values) {
global $validatefunction, $plugintype, $pluginname, $classname;
if (!empty($validatefunction)) {
call_static_method($classname, $validatefunction, $form, $values);
global $plugintype, $pluginname, $classname;
if (method_exists($classname, 'validate_config_options')) {
call_static_method($classname, 'validate_config_options', $form, $values);
}
}
?>
......@@ -388,7 +388,23 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
}
public static function get_config_options() {
return array(); // @todo
$defaultquota = get_config_plugin('artefact', 'file', 'defaultquota');
if (empty($defaultquota)) {
$defaultquota = 1024 * 1024 * 10;
}
return array(
'elements' => array(
'defaultquota' => array(
'title' => get_string('defaultquota', 'artefact.file'),
'type' => 'bytes',
'defaultvalue' => $defaultquota,
),
),
);
}
public static function save_config_options($values) {
set_config_plugin('artefact', 'file', 'defaultquota', $values['defaultquota']);
}
}
......
......@@ -229,13 +229,7 @@ class ArtefactTypeProfile extends ArtefactType {
$public = self::get_public_fields();
$alwaysmandatory = self::get_always_mandatory_fields();
$form = array(
'name' => 'profileprefs',
'method' => 'post',
'ajaxpost' => true,
'plugintype' => 'artefact',
'pluginname' => 'internal',
'renderer' => 'multicolumntable',
'submitfunction' => 'save_config_options',
'elements' => array(
'mandatory' => array(
'title' => ' ',
......@@ -300,10 +294,6 @@ class ArtefactTypeProfile extends ArtefactType {
)
);
$form['elements']['submit'] = array(
'type' => 'submit',
'value' =>get_string('save')
);
return $form;
}
......
Supports Markdown
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