mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-27896 editor - added sanity check to pick wrong context passed to editor creation
This commit is contained in:
parent
e9de1cf49c
commit
f9157eb798
1 changed files with 14 additions and 0 deletions
|
@ -111,6 +111,20 @@ function file_prepare_standard_editor($data, $field, array $options, $context=nu
|
|||
$options['noclean'] = false;
|
||||
}
|
||||
|
||||
//sanity check for passed context. This function doesn't expect $option['context'] to be set
|
||||
//But this function is called before creating editor hence, this is one of the best places to check
|
||||
//if context is used properly. This check notify developer that they missed passing context to editor.
|
||||
if (isset($context) && !isset($options['context'])) {
|
||||
//if $context is not null then make sure $option['context'] is also set.
|
||||
debugging('Context for editor is not set in editoroptions. Hence editor will not respect editor filters', DEBUG_DEVELOPER);
|
||||
} else if (isset($options['context']) && isset($context)) {
|
||||
//If both are passed then they should be equal.
|
||||
if ($options['context']->id != $context->id) {
|
||||
$exceptionmsg = 'Editor context ['.$options['context']->id.'] is not equal to passed context ['.$context->id.']';
|
||||
throw new coding_exception($exceptionmsg);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($itemid) or is_null($context)) {
|
||||
$contextid = null;
|
||||
$itemid = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue