public function display(core_backup_renderer $renderer) {
        global $PAGE;

        $html = '';
        $haserrors = false;
        $url = new moodle_url($PAGE->url, array(
            'restore'   => $this->get_uniqueid(),
            'stage'     => restore_ui::STAGE_PROCESS,
            'substage'  => $this->substage,
            'sesskey'   => sesskey()));
        $html .= html_writer::start_tag('form', array(
            'action'    => $url->out_omit_querystring(),
            'class'     => 'backup-restore',
            'enctype'   => 'application/x-www-form-urlencoded', // Enforce compatibility with our max_input_vars hack.
            'method'    => 'post'));
        foreach ($url->params() as $name => $value) {
            $html .= html_writer::empty_tag('input', array(
                'type'  => 'hidden',
                'name'  => $name,
                'value' => $value));
        }
        switch ($this->substage) {
            case self::SUBSTAGE_PRECHECKS :
                $results = $this->ui->get_controller()->get_precheck_results();
                $info = $this->ui->get_controller()->get_info();
                $haserrors = (!empty($results['errors']));
                $html .= $renderer->precheck_notices($results);
                if (!empty($info->role_mappings->mappings)) {
                    $context = context_course::instance($this->ui->get_controller()->get_courseid());
                    $assignableroles = get_assignable_roles($context, ROLENAME_ALIAS, false);

                    // Get current role mappings.
                    $currentroles = role_fix_names(get_all_roles(), $context);
                    // Get backup role mappings.
                    $rolemappings = $info->role_mappings->mappings;

                    array_map(function($rolemapping) use ($currentroles) {
                        foreach ($currentroles as $role) {
                            // Find matching archetype to determine the backup's shortname for label display.
                            if ($rolemapping->archetype == $role->archetype) {
                                $rolemapping->name = $rolemapping->shortname;
                                break;
                            }
                        }
                        if ($rolemapping->name == null) {
                            $rolemapping->name = get_string('undefinedrolemapping', 'backup', $rolemapping->archetype);
                        }
                    }, $rolemappings);

                    $html .= $renderer->role_mappings($rolemappings, $assignableroles);
                }
                break;
            default:
                throw new restore_ui_exception('backup_ui_must_execute_first');
        }
        $html .= $renderer->substage_buttons($haserrors);
        $html .= html_writer::end_tag('form');

        return $html;
    }