public static function get_add_lock_form($plugin, array $lockplugin = null) {
        global $CFG; // Needed for includes.
        $plugins = core_component::get_plugin_list('cachelock');
        if (!array_key_exists($plugin, $plugins)) {
            throw new coding_exception('Invalid cache lock plugin requested when trying to create a form.');
        }
        $plugindir = $plugins[$plugin];
        $class = 'cache_lock_form';
        if (file_exists($plugindir.'/addinstanceform.php') && in_array('cache_is_configurable', class_implements($class))) {
            require_once($plugindir.'/addinstanceform.php');
            if (class_exists('cachelock_'.$plugin.'_addinstance_form')) {
                $class = 'cachelock_'.$plugin.'_addinstance_form';
                if (!array_key_exists('cache_lock_form', class_parents($class))) {
                    throw new coding_exception('Cache lock plugin add instance forms must extend cache_lock_form');
                }
            }
        }
        return new $class(null, array('lock' => $plugin));
    }