Installation
composer require comsa/sulu-page-export
Ensure your project uses Sulu CMS (v2.x recommended) and follows its standard structure.
Configuration
Add the bundle to config/bundles.php:
Comsa\SuluPageExport\SuluPageExportBundle::class => ['all' => true],
First Use Case Trigger an export via CLI:
php bin/console sulu:page-export:export --page-id=1 --format=html
Outputs exported content to var/exports/page-1.html.
Admin UI Integration Extend Sulu’s admin panel with a custom button:
// src/EventListener/AddExportButtonListener.php
use Comsa\SuluPageExport\Event\ExportButtonEvent;
class AddExportButtonListener
{
public function onExportButton(ExportButtonEvent $event)
{
$event->addButton('export', 'Export Page', 'fas fa-file-export');
}
}
Register in services.yaml:
services:
App\EventListener\AddExportButtonListener:
tags:
- { name: kernel.event_listener, event: sulu_page_export.export_button, method: onExportButton }
Scheduled Exports Use Symfony’s cron or a task scheduler:
# config/packages/sulu_page_export.yaml
sulu_page_export:
scheduled_exports:
- page_id: 1
format: html
cron: "0 3 * * *" # Daily at 3 AM
Custom Formats
Implement Comsa\SuluPageExport\Exporter\ExporterInterface:
class JsonExporter implements ExporterInterface
{
public function export(array $pageData): string
{
return json_encode($pageData, JSON_PRETTY_PRINT);
}
}
Register in services.yaml:
services:
App\Exporter\JsonExporter:
tags: ['sulu_page_export.exporter']
php bin/console sulu:page-export:export --page-id=1 --locale=en_US
sulu_page_export:
media_base_url: "https://cdn.example.com"
$this->container->get('sulu_page_export.exporter')->shouldReceive('export')->once();
Missing Dependencies
Ensure sulu/core and sulu/admin are installed. The package won’t work without them.
Permission Issues
The exporter runs under the ROLE_SULU_ADMIN role by default. Custom roles may break exports:
# Fix: Add to security.yaml
access_control:
- { path: ^/admin/sulu-page-export, roles: ROLE_SULU_ADMIN }
Circular References
Deeply nested page structures (e.g., recursive blocks) may cause infinite loops. Use max_depth in config:
sulu_page_export:
max_export_depth: 5
Log Exports: Enable debug mode to log export paths:
sulu_page_export:
debug: true
Check var/log/dev.log for paths like:
[DEBUG] Export saved to: /var/www/var/exports/page-123.html
Validate Page IDs: Use sulu:page-export:validate to check if a page exists:
php bin/console sulu:page-export:validate --page-id=999
Pre/Post Export Hooks Subscribe to events:
// src/EventListener/CustomExportListener.php
use Comsa\SuluPageExport\Event\PreExportEvent;
class CustomExportListener
{
public function onPreExport(PreExportEvent $event)
{
$event->getPage()->setMetadata(['custom_key' => 'value']);
}
}
Register:
tags:
- { name: kernel.event_listener, event: sulu_page_export.pre_export, method: onPreExport }
Custom Storage Override the default storage adapter:
// src/Exporter/Storage/S3Storage.php
use Comsa\SuluPageExport\Exporter\Storage\StorageInterface;
class S3Storage implements StorageInterface
{
public function save(string $content, string $path): void
{
// Implement S3 logic
}
}
Bind in services.yaml:
Comsa\SuluPageExport\Exporter\Storage\StorageInterface: '@App\Exporter\Storage\S3Storage'
Batch Exports
Use the sulu:page-export:batch command for multiple pages:
php bin/console sulu:page-export:batch --page-ids="1,2,3" --format=html
Warning: Large batches may hit memory limits. Use --chunk-size=10 to process incrementally.
How can I help you explore Laravel packages today?