MDL-67057 core_h5p: Improve displaying errors

This commit is contained in:
Sara Arjona 2019-10-30 08:32:50 +01:00 committed by Andrew Nicols
parent 5a266a579c
commit 285976f1bd
2 changed files with 22 additions and 15 deletions

View File

@ -61,15 +61,18 @@ if (empty($messages->error) && empty($messages->exception)) {
// Add H5P assets to the page.
$h5pplayer->add_assets_to_page();
// Check if there is some error when adding assets to the page.
// Print page HTML.
echo $OUTPUT->header();
// Check if some error has been raised when adding assets to the page. If that's the case, display them above the H5P content.
$messages = $h5pplayer->get_messages();
if (empty($messages->error) && empty($messages->exception)) {
// Print page HTML.
echo $OUTPUT->header();
echo $h5pplayer->output();
if (!empty($messages->exception) || !empty($messages->error)) {
$messages->h5picon = new \moodle_url('/h5p/pix/icon.svg');
echo $OUTPUT->render_from_template('core_h5p/h5perror', $messages);
}
// Display the H5P content.
echo $h5pplayer->output();
} else {
// If there is any error or exception when creating the player, it should be displayed.
$PAGE->set_context(context_system::instance());
@ -80,12 +83,9 @@ if (empty($messages->error) && empty($messages->exception)) {
$PAGE->add_body_class('h5p-embed');
$PAGE->set_pagelayout('embedded');
// Errors can't be printed yet, because some more errors might been added while preparing the output
}
if (!empty($messages->error) || !empty($messages->exception)) {
// Print all the errors.
echo $OUTPUT->header();
// Print all the errors.
$messages->h5picon = new \moodle_url('/h5p/pix/icon.svg');
echo $OUTPUT->render_from_template('core_h5p/h5perror', $messages);
}

View File

@ -21,7 +21,7 @@
Variables required for this template:
* h5picon - The icon
* message - The error message to display.
* message - The error messages to display.
Example context (json):
{
@ -33,7 +33,9 @@
<div class="d-flex h-100 position-relative align-items-center bg-light h5pmessages">
<div class="position-absolute py-2 bg-secondary" style="top: 0px; left: 0px; right: 0px;">
<div class="container">
<img src="{{{h5picon}}}" class="h5picon" alt="{{#str}}h5p, core_h5p{{/str}}" style="width: 50px; height: auto; opacity: 0.5">
{{#h5picon}}
<img src="{{{.}}}" class="h5picon" alt="{{#str}}h5p, core_h5p{{/str}}" style="width: 50px; height: auto; opacity: 0.5">
{{/h5picon}}
</div>
</div>
<div class="container mt-5">
@ -42,9 +44,14 @@
{{{ exception }}}
</div>
{{/exception}}
{{#info}}
<div class="alert alert-block fade in alert-info my-2" role="alert">
{{{ . }}}
</div>
{{/info}}
{{#error}}
<div class="alert alert-block fade in alert-warning my-2" role="alert">
{{{code}}} : {{{ message }}}
{{#code}}{{{code}}} : {{/code}}{{{ message }}}
</div>
{{/error}}
</div>