I'd greatly appreciate any help in creating such a module. I need a field that gets populated with data parsed from another field. I actually have working code for the frontend, but I think I need it for the backend.
I have this simplified code testcase in a successfully loaded module, but it doesn't seem to do anything. I have 2 fields: report_text (type textarea), and report_specialtext (type TextareaSpecial) -- it's meant to grab the contents of report_text, do a simple search and replace, and put the results in report_specialtext:
<?php
class FieldtypeTextareaSpecial extends FieldtypeTextarea {
public static function getModuleInfo() {
return array(
'title' => 'TextareaSpecial',
'version' => 100,
'summary' => 'Field that stores some text',
);
}
public function getSpecialtext($text) {
$out=str_replace("search for this", "replace with this", $text);
return $out;
}
public function init() {
$this->pages->addHookBefore('save', $this, 'calcMethod');
}
public function calcMethod($event) {
$text=$page->report_text;
$specialtext = FieldtypeTextareaSpecial::getSpecialtext($text);
$page->report_specialtext = $specialtext;
$this->message("Hello World! Special text {$specialtext}. Normal text: {$page->report_text}");
}
}
?>
Any help greatly appreciated!