How contentauth/c2pa-drupal works
Project type and purpose
• This is a Drupal 9/10 module (“c2pa-drupal”) that extends the Drupal Field API by providing a custom image field formatter to render C2PA metadata overlays on images, and a client-side JS component that fetches and displays that metadata in the browser.
File structure
• Top-level files:
• c2pa.info.yml, c2pa.install, c2pa.permissions.yml, c2pa.libraries.yml → Drupal module config & hooks
• c2pa.module → any procedural hooks (if used)
• composer.json → PHP dependencies
• CSS/ and JS/ asset directories
• src/Plugin/Field/FieldFormatter/C2paImageFormatter.php → the PHP class registering the “c2pa_image_formatter”
• README, LICENSE, CONTRIBUTING, CODE_OF_CONDUCT → repo metadata
Key insights from README
• Two parts:
a. c2pa_image_formatter: server-side formatter that wraps images in a “c2pa-wrapper” div and attaches CSS
b. c2pa.js: client-side script that, on DOMReady, loads the C2PA SDK & web-component UI from jsdelivr CDN, scans for “c2pa-wrapper” images, extracts metadata, and injects UI overlays
Main components
a. Drupal Backend
• Drupal Core
• c2pa-drupal Module
• YAML config files (.info, .libraries, .install, .permissions)
• PHP Plugin (C2paImageFormatter)
b. Rendering Pipeline
• Image field → passes through C2paImageFormatter → outputs HTML
+ <img> + <link> and <script> tags for assets
c. Assets
• css/c2pa.css (styling for wrapper/UI)
• js/c2pa.js (bootstrapper)
d. Browser Client
• c2pa.js executes on page load
• Dynamically loads external C2PA SDK + web components from CDN
• Scans DOM for .c2pa-wrapper elements
• Processes image data via SDK → extracts metadata → mounts web component UI overlays
e. External Services
• jsdelivr CDN hosting the C2PA SDK and UI web component library
Relationships & data flows
1. Content Editor uploads an image into a Drupal image field.
2. On page render, Drupal Core invokes C2paImageFormatter → wraps the image + attaches CSS & JS via libraries.yml.
3. Browser requests the rendered page → downloads CSS + c2pa.js.
4. c2pa.js (in the browser) fetches the C2PA SDK & web components from the CDN.
5. After dependencies load, the script locates each .c2pa-wrapper, reads embedded C2PA data, and injects interactive UI overlays.
Architectural patterns & principles
• Drupal Plugin API / FieldFormatter pattern (server-side extension point)
• Separation of concerns:
• Server-side PHP handles HTML generation & asset inclusion
• Client-side JS handles runtime processing & UI injection
• Externalization of heavy logic (C2PA SDK) to CDN