Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-57267

Can not have two assign submission plugins using comment API due to static variable in the comment API



    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.2
    • Fix Version/s: None
    • Component/s: Comments
    • Labels:
    • Affected Branches:


      In the comment API there is:

      public function output($return = true) {
      global $PAGE, $OUTPUT;
      static $template_printed;

      $template_printed is checked to display or not display some hidden html node.

      The problem is that this code expect that the first block/plugin/... using a comment API is always displayed. However, when you grade an item, the submission comments column can be collapsed and so not displayed. If you have another block/plugin/... using the comment API, which is loaded after the submission comments plugin is loaded, then $template_printed will be true for the block/plugin/... so the hidden html will never be injected in the Moodle html code, breaking the JS and comments on this page (.i.e you can not expand the comments to see them, the loading comments loader is always turning).

      One way to fix may be:
      if (empty($template_printed) && $this->can_view())

      { $html .= html_writer::tag('div', $this->template, array('style' => 'display:none', 'id' => 'cmt-tmpl')); $template_printed = true; }


      if ($this->can_view())

      { $html .= html_writer::tag('div', $this->template, array('style' => 'display:none', 'id' => 'cmt-tmpl')); $template_printed = true; }

      I think it should work as the comment JS is likely to just pick the first cmt-tmpl (It didn't even produced a JS warning in Chrome inspector when I tested). This is clearly not optimal as it is revelatory of not optimal JS code logic but I think it should not break other comment block/plugin/... (I tested with a block comments and second assigment submission comment plugin).




            • Assignee:
              jerome Jérôme Mouneyrac
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
            • Votes:
              0 Vote for this issue
              1 Start watching this issue


              • Created: