public function get_enrolment_plugins($onlyenabled = true) {
        if ($this->_plugins === null) {
            $this->_plugins = enrol_get_plugins(true);
        }

        if ($onlyenabled) {
            return $this->_plugins;
        }

        if ($this->_allplugins === null) {
            // Make sure we have the same objects in _allplugins and _plugins.
            $this->_allplugins = $this->_plugins;
            foreach (enrol_get_plugins(false) as $name=>$plugin) {
                if (!isset($this->_allplugins[$name])) {
                    $this->_allplugins[$name] = $plugin;
                }
            }
        }

        return $this->_allplugins;
    }