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

$page->requires->jquery() from Filter Results in Error

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.5, 2.6, 2.9.5, 3.0.5
    • Fix Version/s: None
    • Component/s: Filters, JavaScript, Libraries
    • Labels:
    • Affected Branches:
      MOODLE_25_STABLE, MOODLE_26_STABLE, MOODLE_29_STABLE, MOODLE_30_STABLE

      Description

      This issue is related to MDL-41516.

      Attempting to add jquery from a filter's filter.php file using:

          public function setup($page, $context) {
              static $jsinitialised = false;
              if (!$jsinitialised) {
                  $page->requires->jquery();
                  $jsinitialised = true;
              }
          }
      

      results in the following PHP error:

      Can not add jQuery plugins after starting page output!
      line 397 of /lib/outputrequirementslib.php: call to debugging()
      line 341 of /lib/outputrequirementslib.php: call to page_requirements_manager->jquery_plugin()
      line 56 of /filter/rein/filter.php: call to page_requirements_manager->jquery()
      line 255 of /lib/filterlib.php: call to filter_rein->setup()
      line 1120 of /lib/weblib.php: call to filter_manager->setup_page_for_filters()
      line 74 of /filter/rein/renderer.php: call to format_text()
      line 94 of /filter/rein/debug.php: call to filter_rein_renderer->print_debug_accordion()
      

      When the following is tried:

           public function get_required_javascript() {
              parent::get_required_javascript();
              $this->page->requires->jquery();
          }
      

      there is no error and jQuery is not loaded to the page.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              agroshek Amy Groshek
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona), Andrew Nicols, Dongsheng Cai, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated: