How to modify "You are logged in as...(Logout)" link text using CSS

How to modify "You are logged in as...(Logout)" link text using CSS

by Dirk Pfuhl -
Number of replies: 1
EDITED: This comment was split from the original one which was dated from 2008 to 2012, which was quite an old discussion and dealt with Moodle 1.8 - 2-2, however...
WHILST THIS MAY HELP SOME USERS THE CODE HERE HAS NOT BEEN VERIFIED AND MAY NOT WORK.

(Edited by Mary Evans - original submission Thursday, 23 October 2014, 11:13 AM)

Stumbled upon the problem and worked out some CSS tricks, cause by hard coding the moodle core is really not my way.

Here's my markup:

<div class="logininfo">

Sie sind angemeldet als
<a title="Profil anzeigen" href="...">x y</a>
(
<a href="...">Logout</a>
)
</div>

and the CSS:

.login_info {
  visibility: hidden;
  }
.logininfo a {
  visibility: visible;
  }
.logininfo a:first-child {
  optional css rules
  }
.logininfo a:first-child::before {
  content: "custom text";
  }

The trick is to hide the whole login container and make the particular login link visible again. The pseudo class :before allows custom text within (!) the link.

Average of ratings: -
In reply to Dirk Pfuhl

Re: How to modify "You are logged in as...(Logout)" link text using CSS

by Ismaël TANGUY -

Maybe you could use renderers to custom the logininfo div.

  1. At the root of your theme, write the file renderers.php containing :
    <?php
    require_once('renderers/core_renderer.
    php');
  2. Use rendererfactory in config.php :
    $THEME->rendererfactory = 'theme_overridden_renderer_factory';
  3. mkdir a folder called renderers
  4. touch renderers/core_renderer.php
  5. customize the function that create the login, for me that's the code (using FontAwesome icone) :
    <?php
    class theme_YOURTHEME_core_renderer extends theme_bootstrapbase_core_renderer {

    public function login_info($withlinks = null) {
    global $USER, $CFG, $DB, $SESSION;
    if (during_initial_install()) {
    return '';
    }
    if (is_null($withlinks)) {
    $withlinks = empty($this->page->layout_options['nologinlinks']);
    }
    $loginpage = ((string)$this->page->url === get_login_url());
    $course = $this->page->course;
    if (\core\session\manager::is_loggedinas()) {
    $realuser = \core\session\manager::get_realuser();
    $fullname = fullname($realuser, true);
    if ($withlinks) {
    $loginastitle = get_string('loginas');
    $realuserinfo = " [<a href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&amp;sesskey=".sesskey()."\"";
    $realuserinfo .= "title =\"".$loginastitle."\">$fullname</a>] ";
    } else {
    $realuserinfo = " [$fullname] ";
    }
    } else {
    $realuserinfo = '';
    }
    $loginurl = get_login_url();
    if (empty($course->id)) {
    // $course->id is not defined during installation
    return '';
    } else if (isloggedin()) {
    $context = context_course::instance($course->id);
    $fullname = fullname($USER, true);
    // Since Moodle 2.0 this link always goes to the public profile page (not the course profile page)
    if ($withlinks) {
    $linktitle = get_string('viewprofile');
    $username = "<a href=\"$CFG->wwwroot/user/profile.php?id=$USER->id\" title=\"$linktitle\">$fullname</a>";
    } else {
    $username = $fullname;
    }
    if (is_mnet_remote_user($USER) and $idprovider = $DB->get_record('mnet_host', array('id'=>$USER->mnethostid))) {
    if ($withlinks) {
    $username .= " from <a href=\"{$idprovider->wwwroot}\">{$idprovider->name}</a>";
    } else {
    $username .= " from {$idprovider->name}";
    }
    }
    if (isguestuser()) {
    $loggedinas = $realuserinfo.get_string('loggedinasguest');
    if (!$loginpage && $withlinks) {
    $loggedinas .= " <a href=\"$loginurl\">". '<i class="fa fa-sign-in fa-2x"></i>' .'</a>';
    }
    } else if (is_role_switched($course->id)) { // Has switched roles
    $rolename = '';
    if ($role = $DB->get_record('role', array('id'=>$USER->access['rsw'][$context->path]))) {
    $rolename = ': '.role_get_name($role, $context);
    }
    $loggedinas = get_string('loggedinas', 'moodle', $username).$rolename;
    if ($withlinks) {
    $url = new moodle_url('/course/switchrole.php', array('id'=>$course->id,'sesskey'=>sesskey(), 'switchrole'=>0, 'returnurl'=>$this->page-$
    $loggedinas .= ' ('.html_writer::tag('a', get_string('switchrolereturn'), array('href' => $url)).')';
    }
    } else {
    $loggedinas = $realuserinfo.$username;
    if ($withlinks) {
    $loggedinas .= " <a href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".'<i class="fa fa-sign-out fa-2x"></i>'.'</a>';
    }
    }
    } else {
    $loggedinas = get_string('loggedinnot', 'moodle');
    if (!$loginpage && $withlinks) {
    $loggedinas .= " <a href=\"$loginurl\">". '<i class="fa fa-sign-in fa-2x"></i>' .'</a>';
    }
    }
    $loggedinas = '<div class="logininfo">'.$loggedinas.'</div>';
    if (isset($SESSION->justloggedin)) {
    unset($SESSION->justloggedin);
    if (!empty($CFG->displayloginfailures)) {
    if (!isguestuser()) {
    // Include this file only when required.
    require_once($CFG->dirroot . '/user/lib.php');
    if ($count = user_count_login_failures($USER)) {
    $loggedinas .= '<div class="loginfailures">';
    $a = new stdClass();
    $a->attempts = $count;
    $loggedinas .= get_string('failedloginattempts', '', $a);
    if (file_exists("$CFG->dirroot/report/log/index.php") and has_capability('report/log:view', context_system::instance())) {
    $loggedinas .= ' ('.html_writer::link(new moodle_url('/report/log/index.php', array('chooselog' => 1,
    'id' => 0 , 'modid' => 'site_errors')), get_string('logs')).')';
    }
    $loggedinas .= '</div>';
    }
    }
    }
    }
    return $loggedinas;
    }

    }