MDL-76867 core_table: Allow dynamic table filterset to be specified

The previous behaviour guessed the table filterset based on the table's
class name, but this is not very flexible if you wish to create an
abstract table class and use a generic filter for all implementations.

This change adds the ability to specify the filterset class, with the
default behaviour using the table class name as a prefix.
This commit is contained in:
Andrew Nicols 2023-03-14 08:42:39 +08:00
parent fdb1df2bfd
commit f4a48a517b
2 changed files with 10 additions and 1 deletions

View File

@ -201,7 +201,7 @@ class get extends external_api {
throw new \UnexpectedValueException("Table handler class {$tableclass} does not support dynamic updating.");
}
$filtersetclass = "{$tableclass}_filterset";
$filtersetclass = $tableclass::get_filterset_class();
if (!class_exists($filtersetclass)) {
throw new \UnexpectedValueException("The filter specified ({$filtersetclass}) is invalid.");
}

View File

@ -1953,6 +1953,15 @@ class flexible_table {
return $this->filterset;
}
/**
* Get the class used as a filterset.
*
* @return string
*/
public static function get_filterset_class(): string {
return static::class . '_filterset';
}
/**
* Attempt to guess the base URL.
*/