public function create_folder_path_access_controlled_links($context, $component, $filearea, $itemid) {
        global $CFG, $SITE;
        // The fullpath to store the file is generated from the context.
        $contextlist = array_reverse($context->get_parent_contexts(true));
        $fullpath = '';
        $allfolders = [];
        foreach ($contextlist as $ctx) {
            // Prepare human readable context folders names, making sure they are still unique within the site.
            $prevlang = force_current_language($CFG->lang);
            $foldername = $ctx->get_context_name();
            force_current_language($prevlang);

            if ($ctx->contextlevel === CONTEXT_SYSTEM) {
                // Append the site short name to the root folder.
                $foldername .= ' ('.$SITE->shortname.')';
                // Append the relevant object id.
            } else if ($ctx->instanceid) {
                $foldername .= ' (id '.$ctx->instanceid.')';
            } else {
                // This does not really happen but just in case.
                $foldername .= ' (ctx '.$ctx->id.')';
            }

            $foldername = clean_param($foldername, PARAM_FILE);
            $allfolders[] = $foldername;
        }

        $allfolders[] = clean_param($component, PARAM_FILE);
        $allfolders[] = clean_param($filearea, PARAM_FILE);
        $allfolders[] = clean_param($itemid, PARAM_FILE);

        // Extracts the end of the webdavendpoint.
        $parsedwebdavurl = issuer_management::parse_endpoint_url('webdav', $this->issuer);
        $webdavprefix = $parsedwebdavurl['path'];
        $this->systemwebdavclient->open();
        // Checks whether folder exist and creates non-existent folders.
        foreach ($allfolders as $foldername) {
            $fullpath .= '/' . $foldername;
            $isdir = $this->systemwebdavclient->is_dir($webdavprefix . $fullpath);
            // Folder already exist, continue.
            if ($isdir === true) {
                continue;
            }
            $response = $this->systemwebdavclient->mkcol($webdavprefix . $fullpath);

            if ($response != 201) {
                $this->systemwebdavclient->close();
                $details = get_string('contactadminwith', 'repository_nextcloud',
                    get_string('pathnotcreated', 'repository_nextcloud', $fullpath));
                throw new request_exception(array('instance' => $this->repositoryname,
                    'errormessage' => $details));
            }
        }
        $this->systemwebdavclient->close();
        return $fullpath;
    }