MDL-82427 core_filters: Support autoloading of filters

This commit is contained in:
Andrew Nicols 2024-07-09 21:23:50 +08:00
parent fe3b13d51a
commit 534c3e1821
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
3 changed files with 12 additions and 1 deletions

View File

@ -0,0 +1,6 @@
issueNumber: MDL-82427
notes:
core_filters:
- message: >-
Added support for autoloading of filters from `\filter_filtername\filter`. The existing class names are still supported.
type: improved

View File

@ -127,6 +127,11 @@ class filter_manager {
protected function make_filter_object($filtername, $context, $localconfig) {
global $CFG;
$filterclass = "\\filter_{$filtername}\\text_filter";
if (class_exists($filterclass)) {
return new $filterclass($context, $localconfig);
}
$path = $CFG->dirroot .'/filter/'. $filtername .'/filter.php';
if (!is_readable($path)) {
return null;

View File

@ -70,7 +70,7 @@ function filter_get_name($filter) {
function filter_get_all_installed() {
$filternames = array();
foreach (core_component::get_plugin_list('filter') as $filter => $fulldir) {
if (is_readable("$fulldir/filter.php")) {
if (class_exists("\\filter_{$filter}\\text_filter") || is_readable("$fulldir/filter.php")) {
$filternames[$filter] = filter_get_name($filter);
}
}