From 05187c589d6020d9892addfef889281e17a3a47d Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Wed, 18 Oct 2017 15:41:05 +0800 Subject: [PATCH] MDL-60468 calendar: fix event type defaults logic --- calendar/lib.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/calendar/lib.php b/calendar/lib.php index 6fc0e13dba0..f685e02ac44 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -3225,11 +3225,16 @@ function calendar_output_fragment_event_form($args) { true, $data ); - if ($courseid != SITEID) { + + // Let's check first which event types user can add. + calendar_get_allowed_types($allowed, $courseid); + + // If the user is on course context and is allowed to add course events set the event type default to course. + if ($courseid != SITEID && !empty($allowed->courses)) { $data['eventtype'] = 'course'; $data['courseid'] = $courseid; $data['groupcourseid'] = $courseid; - } else if (!empty($categoryid)) { + } else if (!empty($categoryid) && !empty($allowed->category)) { $data['eventtype'] = 'category'; $data['categoryid'] = $categoryid; }