Add editor in local plugin

Re: Add editor in local plugin

by Richard Jones -
Number of replies: 0
Picture of Plugin developers Picture of Testers

Something like this:

public static function add_page_record($data, $context) {
        global $DB;
        $pagecontentsoptions = simplelesson_get_editor_options($context);
        // Insert a dummy record and get the id.
        $data->timecreated = time();
        $data->timemodified = time();
        $data->pagecontents = ' ';
        $data->pagecontentsformat = FORMAT_HTML;
        $dataid = $DB->insert_record('simplelesson_pages', $data);
        $data->id = $dataid;
        // Massage the data into a form for saving.
        $data = file_postupdate_standard_editor(
                $data,
                'pagecontents',
                $pagecontentsoptions,
                $context,
                'mod_simplelesson',
                'pagecontents',
                $data->id);
        // Update the record with full editor data.
        $DB->update_record('simplelesson_pages', $data);
        return $data->id;
    }

pagecontents is the editor area on the relevant form and 'pagecontents' is the file area declared in lib.php:

function simplelesson_get_file_areas($course, $cm, $context) {
    return array('pagecontents' => 'for page files editor content');
}


Average of ratings: Useful (1)