Commit 7bd6a4cf authored by Nigel McNie's avatar Nigel McNie
Browse files

Made the textbox blocktype work.

This involved moving instance_config_save to be in the Blockinstance class, because in order to support Blocktype munging of the config data before being saved, we have to call the method in the child Blocktype class - not normally possible due to PHP's retarded static method calling rules without knowing what blockinstance we are using.

The blocktype itself should now work fine, both when the user has the wysiwyg editor on and off. A smaller version of the editor is used.
parent d644f510
......@@ -73,23 +73,6 @@ abstract class PluginBlocktype extends Plugin {
* validation, should they need it
*/
public static function instance_config_validate(Pieform $form, $values) { }
/**
* This function must be implemented in the subclass if it has config
* $values must contain a hidden 'id' field.
*/
public function instance_config_save(Pieform $form, $values) {
$blockinstance_id = $values['blockinstance'];
// Destroy form values we don't care about
unset($values['sesskey']);
unset($values['blockinstance']);
unset($values['action_configureblockinstance_id_' . $blockinstance_id]);
set_field('block_instance', 'configdata', serialize($values), 'id', $blockinstance_id);
// TODO: fix url
redirect('/viewrework.php?view=1&category=file');
}
public static function has_config() {
return false;
......@@ -215,6 +198,21 @@ class BlockInstance {
throw new ParamOutOfRangeException("Field $field wasn't found in class " . get_class($this));
}
public function instance_config_store(Pieform $form, $values) {
// Destroy form values we don't care about
unset($values['sesskey']);
unset($values['blockinstance']);
unset($values['action_configureblockinstance_id_' . $this->get('id')]);
if (is_callable(array(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_save'))) {
$values = call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_save', $values);
}
set_field('block_instance', 'configdata', serialize($values), 'id', $this->get('id'));
// TODO: fix url
redirect('/viewrework.php?view=1&category=file');
}
/**
* Builds the HTML for the block, inserting the blocktype content at the
* appropriate place
......@@ -225,7 +223,6 @@ class BlockInstance {
public function render($configure=false) {
safe_require('blocktype', $this->get('blocktype'));
if ($configure) {
log_debug('blockinstance being configured is a ' . $this->get('blocktype'));
$elements = call_static_method(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_form', $this);
// Add submit/cancel buttons and helper hidden variable
......@@ -233,17 +230,15 @@ class BlockInstance {
'type' => 'submitcancel',
'value' => array('Save', 'Cancel'),
);
$elements['blockinstance'] = array(
'type' => 'hidden',
'value' => $this->get('id'),
);
$form = array(
'name' => 'cb_' . $this->get('id'),
'validatecallback' => array(generate_class_name('blocktype', $this->get('blocktype')), 'instance_config_validate'),
'successcallback' => array('PluginBlocktype', 'instance_config_save'),
'successcallback' => array($this, 'instance_config_store'),
'elements' => $elements
);
require_once('pieforms/pieform.php');
$pieform = new Pieform($form);
// This is a bit hacky. Because pieforms will take values from
......
......@@ -42,8 +42,8 @@ class PluginBlocktypeTextbox extends PluginBlocktype {
public static function render_instance(BlockInstance $instance) {
$configdata = $instance->get('configdata');
// TODO if wysiwyg off, then format_whitespace, else cleaning needs to be done
return (isset($configdata['text'])) ? format_whitespace($configdata['text']) : '';
$text = (isset($configdata['text'])) ? $configdata['text'] : '';
return $text;
}
public static function has_instance_config() {
......@@ -51,19 +51,28 @@ class PluginBlocktypeTextbox extends PluginBlocktype {
}
public static function instance_config_form($instance) {
log_debug('getting instance config form for ' . $instance->get('id'));
$configdata = $instance->get('configdata');
return array(
'text' => array(
'type' => 'wysiwyg',
'title' => 'Text',
'width' => '100%',
'height' => '50px',
'type' => 'tinywysiwyg',
'width' => '90%',
'height' => '150px',
'defaultvalue' => $configdata['text'],
),
);
}
public static function instance_config_save($values) {
global $USER;
if (!get_account_preference($USER->get('id'), 'wysiwyg')) {
$values['text'] = format_whitespace($values['text']);
}
else {
$values['text'] = clean_text($values['text']);
}
return $values;
}
}
?>
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