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

Cannot use $PAGE->requires->js() with $CFG->themedir in themes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • STABLE backlog
    • 2.4
    • Themes
    • MOODLE_24_STABLE

      $PAGE->requires->js(); uses a path relative to $CFG->dirroot to build the path to the script.

      If an admin sets $CFG->themedir and a theme in that directory has a javascript file that is called with $PAGE->requires->js() it will return an error that the file cannot be found.

      to test the issue do the following:

      #) set $CFG->themedir in config.php
      #) add a theme to the directory set in $CFG->themedir
      #) add a javascript called theme.js to the /javascript/ directory in your theme
      #) add the code below to your theme to:

      if (!empty($CFG->themedir)) {
          $themedir = $CFG->themedir;
      } else {
          $themedir = $CFG->dirroot . '/theme';
      }
      if (file_exists($themedir . '/' . current_theme() . '/javascript/respond.js')) {
          $PAGE->requires->js($themedir . '/' . current_theme() . '/javascript/theme.js');
      }
      

      Result:

      Coding error detected, it must be fixed by a programmer: Attempt to require a JavaScript file that does not exist.

      Expected Result:
      The file will be found (as proven by file_exists() returning true above) and included.

            Unassigned Unassigned
            dwahl Daniel Wahl (Inactive)
            Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:

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