-
Bug
-
Resolution: Not a bug
-
Minor
-
None
-
4.5
-
MOODLE_405_STABLE
I'm using the report builder api in a plugin and wanted to use my plugins renderer in some of the entities, so naturally I try to call $PAGE->get_renderer(...), however, when the report is being rendered in ajax/webservice (usually after submitting a change to a filter value), there is a bit of a chicken and egg problem:
- get_context_for_dynamic_submission loads the report to get the context for the submission to set the context for the page
- In doing so, it loads the report and all entities because creating the report instance calls initialise()
- the entities try to load the renderer, which outputs debugging because the context is not set yet.
There probably needs to be some way to get the reports context, without loading and initialising the entire report.
To Recreate:
- In admin/classes/reportbuilder/local/systemreports/task_logs.php initialise() add:
global $PAGE;
$PAGE->get_renderer('mod_assign');
- Go to the task logs page in your browser /admin/tasklogs.php
- Set any filter and submit
- Confirm debugging is output:
codingerror
Coding error detected, it must be fixed by a programmer: $PAGE->context was not set. You may have forgotten to call require_login() or $PAGE->set_context()
File: /lib/pagelib.php
Line: 573
Stack trace:
Error code: codingerror
* line 573 of /lib/pagelib.php: core\exception\coding_exception thrown
* line 1853 of /lib/pagelib.php: call to moodle_page->magic_get_context()
* line 762 of /lib/pagelib.php: call to moodle_page->initialise_theme_and_output()
* line 1010 of /lib/pagelib.php: call to moodle_page->magic_get_theme()
* line 42 of /admin/classes/reportbuilder/local/systemreports/task_logs.php: call to moodle_page->get_renderer()
* line 106 of /reportbuilder/classes/local/report/base.php: call to core_admin\reportbuilder\local\systemreports\task_logs->initialise()
* line 71 of /reportbuilder/classes/system_report.php: call to core_reportbuilder\local\report\base->__construct()
* line 69 of /reportbuilder/classes/manager.php: call to core_reportbuilder\system_report->__construct()
* line 48 of /reportbuilder/classes/form/filter.php: call to core_reportbuilder\manager::get_report_from_persistent()
* line 57 of /reportbuilder/classes/form/filter.php: call to core_reportbuilder\form\filter->get_report()
* line 68 of /lib/form/classes/dynamic_form.php: call to core_reportbuilder\form\filter->get_context_for_dynamic_submission()
* line 71 of /lib/form/classes/external/dynamic_form.php: call to core_form\dynamic_form->__construct()
* line ? of unknownfile: call to core_form\external\dynamic_form::execute()
* line 253 of /lib/external/classes/external_api.php: call to call_user_func_array()
* line 83 of /lib/ajax/service.php: call to core_external\external_api::call_external_function()
Note depending on your setup you might not actually see the debugging, you can always add an error_log there and check the logs or use xdebug to confirm the line is hit.
Workaround
You can workaround this by checking the state (you can't check the context, since if you check the context and it is not set it will also output debugging) in the reports initialise() function
if ($PAGE->state == moodle_page::STATE_BEFORE_HEADER) { |
$PAGE->set_context($this->get_context()); |
}
|
- has a non-specific relationship to
-
MDL-72974 Make dynamic table aware of page context
-
- Development in progress
-