Merge branch 'MDL-70427' of git://github.com/paulholden/moodle

This commit is contained in:
Andrew Nicols 2021-07-22 11:22:13 +08:00
commit 4c9f590f18
5 changed files with 72 additions and 0 deletions

View file

@ -136,6 +136,28 @@ abstract class task_base {
* @return string
*/
public function get_component() {
if (empty($this->component)) {
// The component should be the root of the class namespace.
$classname = get_class($this);
$parts = explode('\\', $classname);
if (count($parts) === 1) {
$component = substr($classname, 0, strpos($classname, '_task'));
} else {
[$component] = $parts;
}
// Load component information from plugin manager.
if ($component !== 'core' && strpos($component, 'core_') !== 0) {
$plugininfo = \core_plugin_manager::instance()->get_plugin_info($component);
if ($plugininfo && $plugininfo->component) {
$this->set_component($plugininfo->component);
} else {
debugging("Component not set and the class namespace does not match a valid component ({$component}).");
}
}
}
return $this->component;
}