Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

comment MDL-27024 Removed last reference to the comment block within …

…the comment API and used the options properly
  • Loading branch information...
commit 93b86f623967a5eb4ece9a0e22add11c606715e1 1 parent d664d67
@samhemelryk samhemelryk authored
Showing with 30 additions and 4 deletions.
  1. +1 −0  blocks/comments/block_comments.php
  2. +29 −4 comment/lib.php
View
1  blocks/comments/block_comments.php
@@ -49,6 +49,7 @@ function get_content() {
$args->linktext = get_string('showcomments');
$args->notoggle = true;
$args->autostart = true;
+ $args->displaycancel = true;
$comment = new comment($args);
$comment->set_view_permission(true);
View
33 comment/lib.php
@@ -94,6 +94,12 @@ class comment {
*/
protected $autostart = false;
+ /**
+ * If set to true a cancel button will be shown on the form used to submit comments.
+ * @var bool
+ */
+ protected $displaycancel = false;
+
// static variable will be used by non-js comments UI
private static $nonjs = false;
private static $comment_itemid = null;
@@ -198,6 +204,11 @@ public function __construct($options) {
$this->set_autostart($options->autostart);
}
+ // setup displaycancel
+ if (!empty($options->displaycancel)) {
+ $this->set_displaycancel($options->displaycancel);
+ }
+
if (!empty($options->showcount)) {
$count = $this->count();
if (empty($count)) {
@@ -337,6 +348,18 @@ public function set_autostart($newvalue = true) {
}
/**
+ * Sets the displaycancel option
+ *
+ * If set to true then a cancel button will be shown when using the form
+ * to post comments.
+ *
+ * @param bool $newvalue
+ */
+ public function set_displaycancel($newvalue = true) {
+ $this->displaycancel = (bool)$newvalue;
+ }
+
+ /**
* Initialises the JavaScript that enchances the comment API.
*
* @param moodle_page $page The moodle page object that the JavaScript should be
@@ -391,7 +414,9 @@ public function output($return = true) {
$html .= html_writer::start_tag('div', array('class' => 'mdl-left'));
$html .= html_writer::link($this->get_nojslink($PAGE), get_string('showcommentsnonjs'), array('class' => 'showcommentsnonjs'));
- if ($this->env != 'block_comments') {
+ if (!$this->notoggle) {
+ // If toggling is enabled (notoggle=false) then print the controls to toggle
+ // comments open and closed
$html .= html_writer::start_tag('a', array('class' => 'comment-link', 'id' => 'comment-link-'.$this->cid, 'href' => '#'));
$html .= html_writer::empty_tag('img', array('id' => 'comment-img-'.$this->cid, 'src' => $OUTPUT->pix_url('t/collapsed'), 'alt' => $this->linktext, 'title' => $this->linktext));
$html .= html_writer::tag('span', $this->linktext.' '.$this->count, array('id' => 'comment-link-text-'.$this->cid));
@@ -402,8 +427,8 @@ public function output($return = true) {
$html .= html_writer::start_tag('ul', array('id' => 'comment-list-'.$this->cid, 'class' => 'comment-list'));
$html .= html_writer::tag('li', '', array('class' => 'first'));
- if ($this->env == 'block_comments') {
- // in comments block, we print comments list right away
+ if ($this->autostart) {
+ // If autostart has been enabled print the comments list immediatly
$html .= $this->print_comments(0, true, false);
$html .= html_writer::end_tag('ul'); // .comment-list
$html .= $this->get_pagination(0);
@@ -422,7 +447,7 @@ public function output($return = true) {
$html .= html_writer::start_tag('div', array('class' => 'fd', 'id' => 'comment-action-'.$this->cid));
$html .= html_writer::link('#', get_string('savecomment'), array('id' => 'comment-action-post-'.$this->cid));
- if ($this->env != 'block_comments') {
+ if ($this->displaycancel) {
$html .= html_writer::tag('span', ' | ');
$html .= html_writer::link('#', get_string('cancel'), array('id' => 'comment-action-cancel-'.$this->cid));
}
Please sign in to comment.
Something went wrong with that request. Please try again.