diff --git a/enrol/lti/classes/output/renderer.php b/enrol/lti/classes/output/renderer.php
index 7c17e6e82af..57e4427ce75 100644
--- a/enrol/lti/classes/output/renderer.php
+++ b/enrol/lti/classes/output/renderer.php
@@ -263,4 +263,19 @@ class renderer extends plugin_renderer_base {
return parent::render_from_template('enrol_lti/local/ltiadvantage/registration_view',
$tcontext);
}
+
+ /**
+ * Render a warning, indicating to the user that cookies are require but couldn't be set.
+ *
+ * @return string the html.
+ */
+ public function render_cookies_required_notice(): string {
+ $notification = new notification(get_string('cookiesarerequiredinfo', 'enrol_lti'), notification::NOTIFY_WARNING, false);
+ $tcontext = [
+ 'heading' => get_string('cookiesarerequired', 'enrol_lti'),
+ 'notification' => $notification->export_for_template($this),
+ ];
+
+ return parent::render_from_template('enrol_lti/local/ltiadvantage/cookies_required_notice', $tcontext);
+ }
}
diff --git a/enrol/lti/lang/en/enrol_lti.php b/enrol/lti/lang/en/enrol_lti.php
index dce5d50a21a..64d282374c4 100644
--- a/enrol/lti/lang/en/enrol_lti.php
+++ b/enrol/lti/lang/en/enrol_lti.php
@@ -31,6 +31,10 @@ $string['addtocourse'] = 'Add to course';
$string['addtogradebook'] = 'Add to gradebook';
$string['allowframeembedding'] = 'Note: It is recommended that the site administration setting \'Allow frame embedding\' is enabled, so that tools are displayed within a frame rather than in a new window.';
$string['authltimustbeenabled'] = 'Note: This plugin requires the LTI authentication plugin to be enabled too.';
+$string['cookiesarerequired'] = 'Cookies are blocked by your browser';
+$string['cookiesarerequiredinfo'] = 'This tool can\'t be launched because your browser seems to be blocking third-party cookies.
+
+To use this tool, try changing your browser cookie settings or using a different browser.';
$string['copiedtoclipboard'] = '{$a} copied to clipboard';
$string['copytoclipboard'] = 'Copy to clipboard';
$string['couldnotestablishproxy'] = 'Could not establish proxy with consumer.';
diff --git a/enrol/lti/login.php b/enrol/lti/login.php
index 7dbcf1ca77e..33b168bd436 100644
--- a/enrol/lti/login.php
+++ b/enrol/lti/login.php
@@ -88,6 +88,17 @@ if (!isloggedin()) {
'lti_message_hint' => $ltimessagehint,
'client_id' => $_REQUEST['client_id'],
]));
+ if (!cookie_helper::cookies_supported()) {
+ global $OUTPUT, $PAGE;
+ $PAGE->set_context(context_system::instance());
+ $PAGE->set_url(new moodle_url('/enrol/lti/login.php'));
+ $PAGE->set_pagelayout('popup');
+ echo $OUTPUT->header();
+ $renderer = $PAGE->get_renderer('enrol_lti');
+ echo $renderer->render_cookies_required_notice();
+ echo $OUTPUT->footer();
+ die();
+ }
}
// Now, do the OIDC login.
diff --git a/enrol/lti/templates/local/ltiadvantage/cookies_required_notice.mustache b/enrol/lti/templates/local/ltiadvantage/cookies_required_notice.mustache
new file mode 100644
index 00000000000..2b14840d4af
--- /dev/null
+++ b/enrol/lti/templates/local/ltiadvantage/cookies_required_notice.mustache
@@ -0,0 +1,50 @@
+{{!
+ This file is part of Moodle - http://moodle.org/
+
+ Moodle is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Moodle is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Moodle. If not, see