mouseketeers / silverstripe-consent-records
A SilverStripe module to store user consents
Package info
github.com/Mouseketeers/silverstripe-consent-records
Type:silverstripe-vendormodule
pkg:composer/mouseketeers/silverstripe-consent-records
Requires
- php: ^8.3
- silverstripe/admin: ^3
- silverstripe/cms: ^6
- silverstripe/framework: ^6
Requires (Dev)
Suggests
- symbiote/silverstripe-queuedjobs: Runs the consent retention job on a schedule
Provides
None
Conflicts
None
Replaces
None
README
A SilverStripe module for managing user consent records to help with GDPR compliance.
Features
- Store user consent records with detailed information
- Track consent statements, data, and timestamps
- Link to specific legal pages (Terms of Use, Privacy Policy)
- Admin interface for viewing and managing consent records
- Site configuration integration for legal page management
Installation
composer require mouseketeers/silverstripe-consent-records
Usage
Recording Consent
use Mouseketeers\ConsentRecords\ConsentRecord; // Simple consent recording (the statement is 'N/A' unless you pass one) $data = [ 'Email' => 'user@example.com', ]; ConsentRecord::registerConsent($data, [ 'ConsentStatement' => 'I agree to the terms and privacy policy', ]); // Advanced consent recording with custom consent data $consent = [ 'ConsentType' => 'Newsletter', 'ConsentID' => 'newsletter_signup_2024', 'ConsentStatement' => 'I agree to receive newsletters', 'ConsentData' => ['source' => 'homepage', 'campaign' => 'winter2024'] ]; ConsentRecord::registerConsent($data, $consent);
Multiple Consents
$data = [ 'FormData' => ['Name' => 'John Doe', 'Email' => 'john@example.com'], 'Consents' => [ [ 'ConsentType' => 'Newsletter', 'ConsentStatement' => 'I agree to receive newsletters' ], [ 'ConsentType' => 'Marketing', 'ConsentStatement' => 'I agree to marketing communications' ] ] ]; ConsentRecord::registerConsents($data);
Configuration
The module extends SiteConfig to allow you to link legal pages. Go to Settings > Legal Pages in the CMS to configure:
- Terms Page
- Privacy Policy Page
These pages will be automatically linked to consent records for audit purposes.
Default legal page URLs
When no page is selected in Site Settings, getTermsPageLink() and getPrivacyPageLink() fall back to a configured URL. This is useful when the legal pages live outside SilverStripe, or before a page has been selected:
--- Name: my-consent-defaults After: '#consent-records' --- Mouseketeers\ConsentRecords\ConsentRecordsSiteConfigExtension: terms_page_url: "https://example.com/terms-and-conditions" privacy_page_url: "https://example.com/privacy-policy"
The configured URL is only used when no page is selected, and the label passed to the method is used as the link text:
$siteConfig = SiteConfig::current_site_config(); $termsLink = $siteConfig->getTermsPageLink('Terms of Use'); $privacyLink = $siteConfig->getPrivacyPageLink('Privacy Policy');
Cookie banner endpoint
POST /_consent/register (used by mouseketeers/silverstripe-cookie-consent) accepts one consent as JSON
(ConsentType, ConsentID, ConsentStatement, ConsentData, URL). Only types in
CookieConsentConfigurationController.allowed_types (default CookieConsent) are accepted, cross-site
browser requests are rejected, and the body is capped at max_body_bytes. Form data and multi-consent
writes are only possible server-side through ConsentRecord::registerConsents().
Retention and erasure
sake tasks:consent-retention --older-than-days=730 # one-off
sake tasks:consent-retention --consent-id=jo@example.com # erasure request
sake tasks:consent-retention # uses retention_days below
Records are kept until you say otherwise. To delete them automatically, set a period and start the job:
Mouseketeers\ConsentRecords\ConsentRetention: retention_days: 730 # 0 (default) = never delete job_interval_days: 7 # how often the job runs
sake tasks:consent-retention --schedule
The job needs symbiote/silverstripe-queuedjobs and its
cron/worker. It deletes records older than retention_days, then queues its own next run, so --schedule is
only needed once (running it again is harmless). With retention_days: 0 it does nothing and stops repeating.
Only the consent records are deleted by this module. Other modules can delete the data that belongs to them:
ConsentRetention calls an onBeforePurge(array $records) extension hook with each batch (500 records, see
batch_size) just before it is deleted. consent-userforms uses it to delete the linked UserForms submissions.
Personal data outside that, such as submissions of forms with no consent field, is not touched; delete it from
your own project, e.g. by calling ConsentRetention::purge($days) from your own job.
Module compatibility
| consent-records | consent-forms | consent-userforms | cookie-consent | SilverStripe |
|---|---|---|---|---|
| 5.x | 5.x | 4.x | 4.x | 6 |
| 4.x (support) | 4.x | 3.x | 3.x | 5.4 |
cookie-consent needs the _consent/register route, which exists from consent-records 5.0 (SilverStripe 6), 4.1 (SilverStripe 5.4) and 2.2 (SilverStripe 4). Earlier releases expose /consent/register.
Database Fields
ConsentID: Unique identifier for the consentConsentStatement: The actual consent text (HTML stripped)ConsentData: Additional data stored as JSONConsentType: Type of consent (e.g., 'TermsAndPrivacyConsent', 'Newsletter')Source: What wrote the record (cookie-banner,userform, …), set by the serverSubmissionID: ID of the originating submission, e.g. a UserFormsSubmittedForm(0 if none)URL: The URL where consent was givenTermsPageID/Version: Link to Terms page at time of consentPrivacyPageID/Version: Link to Privacy page at time of consent
Requirements
- SilverStripe Framework ^6, CMS ^6, Admin ^3
- PHP ^8.3
SilverStripe 5.4 users stay on the 4.x line (support/4.x).
License
BSD-3-Clause