public static function export_user_data(approved_contextlist $contextlist) {
        global $DB;

        // If the user has block_community data, then only the User context should be present so get the first context.
        $contexts = $contextlist->get_contexts();
        if (count($contexts) == 0) {
            return;
        }
        $context = reset($contexts);

        // Sanity check that context is at the User context level, then get the userid.
        if ($context->contextlevel !== CONTEXT_USER) {
            return;
        }
        $userid = $context->instanceid;

        // The block_community data export is organised in: {User Context}/Community Finder/My communities/data.json.
        $subcontext = [
            get_string('pluginname', 'block_community'),
            get_string('mycommunities', 'block_community')
        ];

        $sql = "SELECT bc.id as id,
                       bc.coursename as name,
                       bc.coursedescription as description,
                       bc.courseurl as url,
                       bc.imageurl as imageurl
                  FROM {block_community} bc
                 WHERE bc.userid = :userid
              ORDER BY bc.coursename";

        $params = [
            'userid' => $userid
        ];

        $communities = $DB->get_records_sql($sql, $params);

        $data = (object) [
            'communities' => $communities
        ];

        writer::with_context($context)->export_data($subcontext, $data);
    }