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

Code in renderers should not refer to global $PAGE or global $OUTPUT

    XMLWordPrintable

Details

    • MOODLE_37_STABLE, MOODLE_38_STABLE
    • MOODLE_39_STABLE
    • Hide

      I don't think there is useful manual testing to do here. The only thing is to ensure this does not introduce regressions, and that is what the automated tests are for.

      Show
      I don't think there is useful manual testing to do here. The only thing is to ensure this does not introduce regressions, and that is what the automated tests are for.

    Description

      Code in a renderer should never refer to global $PAGE. The page this renderer is rendering should be accessed as $this->page.

      Similarly, never refer to global $OUTPUT. If you need to access the core renderer from a plugin renderer, use $this->output.

      99% of the time this does not matter, because each script is only rendering its own output. However, in theory it should be possible to write a script like to archive all quiz results:

      foreach ($quizattempts as $attempt) {
          $reviewpage = new moodle_page();
          // Setup $reviewpage;
          $output = $reviewpage->get_renderer('mod_quiz');
          $html = $output->render_review_page($attempt);
          // Store $html in a zip file.
      }
      

      If renderers refer to the global variables, this breaks .

      We really ought to have a CodeChecker rule to catch people making this mistake, since it is clearly very easy to do.

      Attachments

        Issue Links

          Activity

            People

              timhunt Tim Hunt
              timhunt Tim Hunt
              Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
              Sara Arjona (@sarjona) Sara Arjona (@sarjona)
              CiBoT CiBoT
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Laurent David, Raquel Ortega, Sara Arjona (@sarjona), Huong Nguyen, Bas Brands, Mathew May
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                15/Jun/20

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 3 hours, 5 minutes
                  3h 5m