Merge branch 'MDL-59919-master' of git://github.com/ryanwyllie/moodle
authorJun Pataleta <jun@moodle.com>
Tue, 12 Sep 2017 06:58:06 +0000 (14:58 +0800)
committerJun Pataleta <jun@moodle.com>
Tue, 12 Sep 2017 06:58:06 +0000 (14:58 +0800)
1  2 
calendar/classes/local/event/forms/create.php
calendar/lib.php

@@@ -41,7 -59,9 +59,8 @@@ class create extends \moodleform 
          global $PAGE;
  
          $mform = $this->_form;
 -        $haserror = !empty($this->_customdata['haserror']);
          $starttime = isset($this->_customdata['starttime']) ? $this->_customdata['starttime'] : 0;
+         $editoroptions = !(empty($this->_customdata['editoroptions'])) ? $this->_customdata['editoroptions'] : null;
          $eventtypes = calendar_get_all_allowed_types();
  
          if (empty($eventtypes)) {
@@@ -3452,22 -3530,30 +3452,27 @@@ function calendar_get_view(\calendar_in
   * @return string The rendered mform fragment.
   */
  function calendar_output_fragment_event_form($args) {
-     global $CFG, $OUTPUT;
-     require_once($CFG->dirroot.'/calendar/event_form.php');
+     global $CFG, $OUTPUT, $USER;
  
      $html = '';
-     $data = null;
+     $data = [];
      $eventid = isset($args['eventid']) ? clean_param($args['eventid'], PARAM_INT) : null;
      $starttime = isset($args['starttime']) ? clean_param($args['starttime'], PARAM_INT) : null;
 +    $courseid = isset($args['courseid']) ? clean_param($args['courseid'], PARAM_INT) : null;
      $event = null;
      $hasformdata = isset($args['formdata']) && !empty($args['formdata']);
-     $formoptions = [];
+     $context = \context_user::instance($USER->id);
+     $editoroptions = \core_calendar\local\event\forms\create::build_editor_options($context);
+     $formoptions = ['editoroptions' => $editoroptions];
+     $draftitemid = 0;
  
      if ($hasformdata) {
          parse_str(clean_param($args['formdata'], PARAM_TEXT), $data);
+         if (isset($data['description']['itemid'])) {
+             $draftitemid = $data['description']['itemid'];
+         }
      }
  
 -    if (isset($args['haserror'])) {
 -        $formoptions['haserror'] = clean_param($args['haserror'], PARAM_BOOL);
 -    }
 -
      if ($starttime) {
          $formoptions['starttime'] = $starttime;
      }
              true,
              $data
          );
 +        if ($courseid != SITEID) {
 +            $data['eventtype'] = 'course';
 +            $data['courseid'] = $courseid;
 +            $data['groupcourseid'] = $courseid;
 +        }
 +        $mform->set_data($data);
      } else {
          $event = calendar_event::load($eventid);
+         $mapper = new \core_calendar\local\event\mappers\create_update_form_mapper();
+         $eventdata = $mapper->from_legacy_event_to_data($event);
+         $data = array_merge((array) $eventdata, $data);
          $event->count_repeats();
          $formoptions['event'] = $event;
+         $data['description']['text'] = file_prepare_draft_area(
+             $draftitemid,
+             $event->context->id,
+             'calendar',
+             'event_description',
+             $event->id,
+             null,
+             $data['description']['text']
+         );
+         $data['description']['itemid'] = $draftitemid;
          $mform = new \core_calendar\local\event\forms\update(
              null,
              $formoptions,