|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is a Symfony 7.2 application that demonstrates integration with DotCMS using the DotCMS PHP SDK. It serves as a headless CMS frontend that dynamically renders pages, layouts, containers, and content from DotCMS. |
| 8 | + |
| 9 | +## Key Architecture Components |
| 10 | + |
| 11 | +### Core Integration Pattern |
| 12 | +- **Catch-all routing**: Single controller (`CatchAllController`) handles all page requests via a catch-all route |
| 13 | +- **Service layer**: `DotCMSService` wraps the DotCMS PHP SDK client for consistent API access |
| 14 | +- **Twig extensions**: `DotCMSExtension` provides template functions for rendering DotCMS content |
| 15 | +- **Exception mapping**: DotCMS SDK exceptions are mapped to appropriate Symfony HTTP exceptions |
| 16 | +- **UVE integration**: Universal Visual Editor enables content editing capabilities |
| 17 | +- **Frontend architecture**: Stimulus controllers handle JavaScript functionality and UVE interactions |
| 18 | + |
| 19 | +### DotCMS Integration Flow |
| 20 | +1. Symfony router matches catch-all route to `CatchAllController::show()` |
| 21 | +2. Controller extracts path and optional query parameters (language_id, mode, personaId, publishDate) |
| 22 | +3. `DotCMSService` creates page request with parameters and fetches from DotCMS API |
| 23 | +4. Page data (layout, containers, contentlets) is passed to Twig templates |
| 24 | +5. Twig extension functions render content-type specific templates or fall back to SDK utilities |
| 25 | + |
| 26 | +### Template Architecture |
| 27 | +- `templates/page.html.twig`: Main page template that renders layout rows/columns |
| 28 | +- `templates/dotcms/container.twig`: Container template with contentlet rendering |
| 29 | +- `templates/dotcms/content-types/`: Content-type specific templates (banner.twig, product.twig, etc.) |
| 30 | +- `templates/dotcms/header.twig`: Navigation rendering using DotCMS navigation API |
| 31 | + |
| 32 | +## Development Commands |
| 33 | + |
| 34 | +### Start Development Server |
| 35 | +```bash |
| 36 | +symfony server:start |
| 37 | +``` |
| 38 | + |
| 39 | +### Testing |
| 40 | +```bash |
| 41 | +# Run all tests |
| 42 | +vendor/bin/phpunit |
| 43 | + |
| 44 | +# Or using Symfony's PHPUnit bridge |
| 45 | +php bin/phpunit |
| 46 | +``` |
| 47 | + |
| 48 | +### Dependency Management |
| 49 | +```bash |
| 50 | +# Install dependencies |
| 51 | +composer install |
| 52 | + |
| 53 | +# For local SDK development |
| 54 | +COMPOSER=composer.dev.json composer install |
| 55 | +``` |
| 56 | + |
| 57 | +### Cache and Assets |
| 58 | +```bash |
| 59 | +# Clear cache |
| 60 | +php bin/console cache:clear |
| 61 | + |
| 62 | +# Install assets |
| 63 | +php bin/console assets:install |
| 64 | + |
| 65 | +# Build frontend assets with Webpack Encore |
| 66 | +npm run dev |
| 67 | + |
| 68 | +# Build for production |
| 69 | +npm run build |
| 70 | + |
| 71 | +# Watch for changes during development |
| 72 | +npm run watch |
| 73 | + |
| 74 | +# Start development server with asset watching |
| 75 | +npm run dev-server |
| 76 | +``` |
| 77 | + |
| 78 | +## Configuration |
| 79 | + |
| 80 | +### Environment Variables |
| 81 | +- `DOTCMS_HOST`: DotCMS instance URL (default: https://demo.dotcms.com) |
| 82 | +- `DOTCMS_API_KEY`: API key for DotCMS authentication |
| 83 | + |
| 84 | +### Service Configuration |
| 85 | +DotCMS client is configured in `config/services.yaml`: |
| 86 | +- `dotcms.client`: Main DotCMSClient service |
| 87 | +- `dotcms.config`: Configuration with host, API key, and client options |
| 88 | +- Client timeout: 30 seconds, SSL verification enabled |
| 89 | +- Debug logging enabled for development |
| 90 | + |
| 91 | +## Key Files and Their Purpose |
| 92 | + |
| 93 | +### Controllers |
| 94 | +- `src/Controller/CatchAllController.php`: Handles all page requests, fetches from DotCMS, maps exceptions |
| 95 | + |
| 96 | +### Services |
| 97 | +- `src/Service/DotCMSService.php`: Wraps DotCMS client, provides page and navigation methods with parameter support |
| 98 | + |
| 99 | +### Twig Extensions |
| 100 | +- `src/Twig/DotCMSExtension.php`: Template functions for content rendering, HTML attributes, grid classes |
| 101 | + |
| 102 | +### Templates |
| 103 | +- `templates/page.html.twig`: Main page template with layout rendering |
| 104 | +- `templates/dotcms/container.twig`: Container and contentlet rendering with DotCMS attributes |
| 105 | +- `templates/dotcms/content-types/`: Content-type specific templates |
| 106 | +- `templates/base.html.twig`: Base template with UVE script integration |
| 107 | + |
| 108 | +### Frontend Assets |
| 109 | +- `assets/app.js`: Main JavaScript entry point |
| 110 | +- `assets/controllers/dotcms_edit_controller.js`: Stimulus controller for UVE edit functionality |
| 111 | +- `webpack.config.js`: Webpack Encore configuration for asset compilation |
| 112 | +- `package.json`: Node.js dependencies including @dotcms/uve and @dotcms/types |
| 113 | + |
| 114 | +## Working with Content Types |
| 115 | + |
| 116 | +To add support for new content types: |
| 117 | +1. Create template in `templates/dotcms/content-types/{content-type}.twig` |
| 118 | +2. Template receives `content` variable (Contentlet object) and `dotcms_host` variable |
| 119 | +3. The `generateHtmlBasedOnProperty` function automatically finds and renders the template |
| 120 | +4. Falls back to SDK's `simpleContentHtml` if no template exists |
| 121 | + |
| 122 | +## UVE (Universal Visual Editor) Integration |
| 123 | + |
| 124 | +The application includes DotCMS UVE integration for content editing: |
| 125 | + |
| 126 | +### Key Components |
| 127 | +- **UVE Script**: Loaded in `templates/base.html.twig` from DotCMS host |
| 128 | +- **Edit Controller**: `assets/controllers/dotcms_edit_controller.js` handles edit functionality |
| 129 | +- **Dependencies**: Uses `@dotcms/uve` and `@dotcms/types` packages |
| 130 | +- **Mode Detection**: Edit buttons only appear when in UVE edit mode |
| 131 | + |
| 132 | +### Stimulus Controller Features |
| 133 | +- **Auto-hide**: Edit buttons are hidden when not in edit mode |
| 134 | +- **Content Editing**: Calls `editContentlet()` function from UVE library |
| 135 | +- **State Management**: Uses `getUVEState()` to detect current mode |
| 136 | + |
| 137 | +### Setup Requirements |
| 138 | +1. UVE script must be loaded from DotCMS host |
| 139 | +2. Content must have proper data attributes for UVE identification |
| 140 | +3. Edit controllers must be attached to editable content elements |
| 141 | + |
| 142 | +## Error Handling |
| 143 | + |
| 144 | +The application maps DotCMS SDK exceptions to Symfony HTTP exceptions: |
| 145 | +- `HttpException` codes 400, 401, 404, 500, 503 map to corresponding Symfony exceptions |
| 146 | +- `ResponseException` maps to `ServiceUnavailableHttpException` |
| 147 | +- All unmapped exceptions default to `ServiceUnavailableHttpException` |
| 148 | + |
| 149 | +## Development Notes |
| 150 | + |
| 151 | +- Uses Symfony 7.2 with PHP 8.2+ requirement |
| 152 | +- Includes Doctrine ORM, Twig, Stimulus, and other standard Symfony components |
| 153 | +- PHPUnit configured for testing with Symfony bridge |
| 154 | +- Webpack Encore handles frontend asset compilation and optimization |
| 155 | +- Stimulus controllers provide JavaScript functionality |
| 156 | +- UVE integration enables content editing capabilities |
| 157 | +- Development uses local PHP SDK when `composer.dev.json` is specified |
0 commit comments