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

jQuery libraries cannot be included in blocks when themes have a call to 'body_attributes()'

XMLWordPrintable

    • MOODLE_25_STABLE, MOODLE_26_STABLE
    • MOODLE_25_STABLE
    • Hide

      None at this moment in time.

      Show
      None at this moment in time.
    • Hide

      Open blocks/html/block_html.php, find the block_html class and add:

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

      Checking against all themes:

      • Turn editing on;
      • Add an HTML block;
      • Confirm that no errors were displayed - those relating to jQuery being called after output has started
      Show
      Open blocks/html/block_html.php, find the block_html class and add: public function get_required_javascript() { parent::get_required_javascript(); $this->page->requires->jquery(); $this->page->requires->jquery_plugin('ui'); $this->page->requires->jquery_plugin('ui-css'); } Checking against all themes: Turn editing on; Add an HTML block; Confirm that no errors were displayed - those relating to jQuery being called after output has started

      On the themes forum an issue has been highlighted in post https://moodle.org/mod/forum/discuss.php?d=236254 where the stack trace given in the custom block is:

      Can not add jQuery plugins after starting page output!
       
      line 397 of /lib/outputrequirementslib.php: call to debugging()
      line 11 of /blocks/myblock/block_myblock.php: call to page_requirements_manager->jquery_plugin()
      line 293 of /blocks/moodleblock.class.php: call to block_myblock->get_required_javascript()
      line 238 of /blocks/moodleblock.class.php: call to block_base->formatted_contents()
      line 951 of /lib/blocklib.php: call to block_base->get_content_for_output()
      line 1003 of /lib/blocklib.php: call to block_manager->create_block_contents()
      line 353 of /lib/blocklib.php: call to block_manager->ensure_content_created()
      line 3071 of /lib/outputrenderers.php: call to block_manager->region_has_content()
      line 3107 of /lib/outputrenderers.php: call to core_renderer->body_css_classes()
      line 49 of /theme/clean/layout/columns3.php: call to core_renderer->body_attributes()
      line 850 of /lib/outputrenderers.php: call to include()
      line 780 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
      line 101 of /index.php: call to core_renderer->header()
      

      It is stated that the jQuery libraries have been included correctly:

          public function get_required_javascript() {
              parent::get_required_javascript();
       
              $this->page->requires->jquery();
              $this->page->requires->jquery_plugin('ui');
              $this->page->requires->jquery_plugin('ui-css');
              $this->page->requires->js('/blocks/myblock/myscript.js');
          }
      

      Which matches the information given on http://docs.moodle.org/dev/jQuery#jQuery_UI_in_add-on_block.

      It looks like with the 'Clean' theme that test '4' on MDL-15727 will now fail because the method 'body_attributes()' was added in MDL-39838 and applied to the 'Clean' theme in MDL-40089 after the tests on MDL-15727 were run. Therefore I suspect a regression has taken place.

            dobedobedoh Andrew Lyons
            gb2048 Gareth J Barnard
            Sam Hemelryk Sam Hemelryk
            Damyon Wiese Damyon Wiese
            Jason Fowler Jason Fowler
            Votes:
            1 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.