diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index fc1cedc3c73..1bd2d99657c 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -4045,6 +4045,7 @@ EOD; if ($USER->id != $user->id && has_capability('moodle/site:sendmessage', $context)) { $userbuttons = array( 'messages' => array( + 'buttontype' => 'message', 'title' => get_string('message', 'message'), 'url' => new moodle_url('/message/index.php', array('id' => $user->id)), 'image' => 'message', @@ -4090,6 +4091,10 @@ EOD; $html .= html_writer::start_div('btn-group header-button-group'); foreach ($contextheader->additionalbuttons as $button) { if (!isset($button->page)) { + // Include js for messaging. + if ($button['buttontype'] === 'message') { + message_messenger_requirejs(); + } $image = $this->pix_icon($button['formattedimage'], $button['title'], 'moodle', array( 'class' => 'iconsmall', 'role' => 'presentation' diff --git a/user/profile.php b/user/profile.php index a57918511a3..32168f5d268 100644 --- a/user/profile.php +++ b/user/profile.php @@ -103,13 +103,6 @@ $PAGE->set_context($context); $PAGE->set_pagelayout('mypublic'); $PAGE->set_pagetype('user-profile'); -// Load the JS to send a message. -$cansendmessage = isloggedin() && has_capability('moodle/site:sendmessage', $context) - && !empty($CFG->messaging) && !isguestuser() && !isguestuser($user) && ($USER->id != $user->id); -if ($cansendmessage) { - message_messenger_requirejs(); -} - // Set up block editing capabilities. if (isguestuser()) { // Guests can never edit their profile. $USER->editing = $edit = 0; // Just in case. @@ -455,13 +448,5 @@ echo ""; // Closing desriptionbox and userprofilebox. echo $OUTPUT->custom_block_region('content'); -// Print messaging link if allowed. -if ($cansendmessage) { - $sendurl = new moodle_url('/message/index.php', array('id' => $user->id)); - echo '
'; - echo html_writer::link($sendurl, get_string('messageselectadd'), message_messenger_sendmessage_link_params($user)); - echo '
'; -} - echo ''; // Userprofile class. echo $OUTPUT->footer(); diff --git a/user/view.php b/user/view.php index 12a98b3018d..96b0a2e21c1 100644 --- a/user/view.php +++ b/user/view.php @@ -83,12 +83,6 @@ $PAGE->set_other_editing_capability('moodle/course:manageactivities'); // of inhereting the pagetype will lead to an incorrect docs location. $PAGE->set_docs_path('user/profile'); -$cansendmessage = isloggedin() && has_capability('moodle/site:sendmessage', $usercontext) - && !empty($CFG->messaging) && !isguestuser() && !isguestuser($user) && ($USER->id != $user->id); -if ($cansendmessage) { - message_messenger_requirejs(); -} - $isparent = false; if (!$currentuser and !$user->deleted @@ -378,16 +372,6 @@ if (has_capability('moodle/user:viewlastip', $usercontext) && !isset($hiddenfiel } echo html_writer::end_tag('dl'); echo ""; // Closing desriptionbox and userprofilebox. -// Print messaging link if allowed. -if ($cansendmessage) { - echo '
'; - $sendmessageurl = new moodle_url('/message/index.php', array('id' => $user->id)); - if ($courseid) { - $sendmessageurl->param('viewing', MESSAGE_VIEW_COURSE. $courseid); - } - echo html_writer::link($sendmessageurl, get_string('messageselectadd'), message_messenger_sendmessage_link_params($user)); - echo '
'; -} if (empty($CFG->forceloginforprofiles) || $currentuser || has_capability('moodle/user:viewdetails', $usercontext) || has_coursecontact_role($id)) {