public static function setup_for_plan($userid, moodle_url $url, $plan = null, $subtitle = '', $returntype = null) {
        global $PAGE, $USER;

        // Check that the user is a valid user.
        $user = core_user::get_user($userid);
        if (!$user || !core_user::is_real_user($userid)) {
            throw new \moodle_exception('invaliduser', 'error');
        }

        $context = context_user::instance($user->id);

        $plansurl = new moodle_url('/admin/tool/lp/plans.php', array('userid' => $userid));
        $planurl = null;
        if ($plan) {
            $planurl = new moodle_url('/admin/tool/lp/plan.php', array('id' => $plan->get('id')));
        }

        $returnurl = $plansurl;
        if ($returntype != 'plans' && $planurl) {
            $returnurl = $planurl;
        }

        $PAGE->navigation->override_active_url($plansurl);
        $PAGE->set_context($context);

        // If not his own plan, we want to extend the navigation for the user.
        $iscurrentuser = ($USER->id == $user->id);
        if (!$iscurrentuser) {
            $PAGE->navigation->extend_for_user($user);
            $PAGE->navigation->set_userid_for_parent_checks($user->id);
        }

        if (!empty($plan)) {
            $title = format_string($plan->get('name'), true, array('context' => $context));
        } else {
            $title = get_string('learningplans', 'tool_lp');
        }

        $PAGE->set_pagelayout('standard');
        $PAGE->set_url($url);
        $PAGE->set_title($title);
        $PAGE->set_heading($title);

        if (!empty($plan)) {
            $PAGE->navbar->add($title, $planurl);
            if (!empty($subtitle)) {
                $PAGE->navbar->add($subtitle, $url);
            }
        } else if (!empty($subtitle)) {
            // We're in a sub page without a specific plan.
            $PAGE->navbar->add($subtitle, $url);
        }

        return array($title, $subtitle, $returnurl);
    }