This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Craft CMS plugin called "oEmbed" that extracts media information from websites like YouTube videos, Twitter statuses, and blog articles. The plugin provides field types, GraphQL support, caching, and GDPR compliance features.
IMPORTANT: All development and testing must be done using Docker. The project requires a PostgreSQL database and specific environment setup that is only available through the Docker containers.
- Start development environment:
docker compose up -d - Verify containers are running:
docker ps - Copy test environment:
cp tests/.env.example tests/.env - Configure API tokens in
.envfor Meta, Twitter, etc. for full test coverage
- Run all tests:
docker exec app vendor/bin/codecept run - Run specific test file:
docker exec app vendor/bin/codecept run {your_file} - Run with coverage:
docker exec app sh -c "XDEBUG_MODE=coverage vendor/bin/codecept run --coverage" - Run embed-specific tests:
docker exec app vendor/bin/codecept run tests/unit/embeds/
- Access container shell:
docker exec -it app sh - Run commands inside container:
docker exec app [command]
- Install dependencies:
docker exec app composer install - Check logs:
docker logs app - Stop environment:
docker compose down
src/Oembed.php- Main plugin class that registers services, fields, variables, and event handlers
src/services/OembedService.php- Core service handling URL parsing, embed extraction, caching, and GDPR compliance- Uses the
embed/embedpackage for oEmbed protocol support - Handles YouTube, Vimeo, and other provider-specific logic
- Implements fallback adapters for unsupported URLs
- Manages DOM manipulation for iframe customization
- Uses the
src/fields/OembedField.php- Custom Craft CMS field type for oEmbed URLs- Provides CP interface with preview functionality
- GraphQL support with configurable options
- URL validation and normalization
src/models/OembedModel.php- Data model for oEmbed field values- Lazy loading of embed data
- Template-friendly methods (render, embed, media, valid)
src/models/Settings.php- Plugin settings model
src/adapters/EmbedAdapter.php- Primary adapter using embed/embed librarysrc/adapters/FallbackAdapter.php- Fallback for unsupported URLs
- Configurable caching with different durations for successful/failed requests
- Custom cache key props for additional field caching
- Default cached properties include title, description, code, dimensions, provider info
- YouTube no-cookie domain switching
- Vimeo DNT parameter support
- CookieBot integration attributes
- Configurable privacy settings
- Support for autoplay, loop, mute, rel parameters
- YouTube playlist parameter handling for loops
- Custom iframe attributes via options
src/gql/OembedFieldResolver.php- GraphQL field resolversrc/gql/OembedFieldTypeGenerator.php- GraphQL type generator- Supports JSON-encoded options and cache props arguments
The plugin supports multiple template access methods:
- Field methods:
entry.field.render(),entry.field.embed(),entry.field.media() - Variable methods:
craft.oembed.render(url, options, cacheFields) - Options support both legacy format and new params/attributes structure
- Uses Codeception framework with Craft CMS testing module
- Functional tests in
tests/functional/ - Unit tests in
tests/unit/including provider-specific tests - Coverage reports generated in
tests/_output/coverage/
- Plugin supports Craft CMS 4.0+ and 5.0+
- Requires PHP 8.2+
- Uses
embed/embedv4.4+ for oEmbed protocol support - Many providers require embed URLs rather than standard URLs for proper oEmbed data
- Failed requests are cached for shorter duration (15 minutes vs 1 hour)