protected static function set_custom_types(array $types) {
        global $CFG;
        // Check the setting hasn't been forced.
        if (array_key_exists('customfiletypes', $CFG->config_php_settings)) {
            throw new coding_exception('Cannot set custom filetypes because they ' .
                    'are defined in config.php');
        }
        if (empty($types)) {
            unset_config('customfiletypes');
        } else {
            set_config('customfiletypes', json_encode(array_values($types)));
        }

        // Clear the cached type list.
        self::reset_caches();
    }