alengo/sulu-media-extra-bundle
Sulu CMS media utilities: sync @2x crops to base formats automatically, generate image-formats.xml entries from YAML, backfill existing @2x format options, and rename media with dry-run support.
Check version compatibility first (added in 1.1.0):
1.1.0 targets Sulu 3.1+ / Symfony 8.1+.composer require "alengo/sulu-media-extra-bundle:^1.0"
composer why-not alengo/sulu-media-extra-bundle 1.1.0
Installation:
composer require alengo/sulu-media-extra-bundle
Register the bundle in config/bundles.php:
Alengo\SuluMediaExtraBundle\AlengoMediaExtraBundle::class => ['all' => true],
First Use Case:
@2x crop sync (automatic): No action required—it activates immediately after installation.bin/adminconsole alengo:media:image-formats:generate
Create a YAML file at config/app/image-formats.yaml (see README for format).1.1.0 is a compatibility release: no new commands, options, or public API changes were announced. Everything below applies to
^1.0and^1.1alike—only the framework floor moved.
@2x Crop Synchronization@2x formats in image-formats.xml (e.g., 800x@2x).@2x formats in the Sulu admin panel.800x).@1x and @2x crops must align.800x@2x to your image-formats.xml and let the bundle handle the rest.config/app/image-formats.yaml (e.g., 400x300, 800x).bin/adminconsole alengo:media:image-formats:generate --source=config/app/image-formats.yaml
config/image-formats.xml (avoids overwriting existing configs).image-format-options:duplicate if migrating existing crops.@2x crops exist but base formats lack crops, run:
bin/adminconsole alengo:media:image-format-options:duplicate
800x, 400x300).bin/adminconsole alengo:media:rename <mediaId> "new-name" --locale=en
bin/adminconsole alengo:media:rename <mediaId> "new-name" --dry-run
subVersion to invalidate caches.Upgrading to 1.1.0 on an older stack:
composer update on a Sulu 3.0 / Symfony 8.0 project will either fail resolution or (worse, with loose constraints elsewhere) drag other packages forward.^1.0. Run bin/adminconsole cache:clear and a migration check after the bump.@2x crop in the admin UI and confirm the base format is still mirrored.XML Overwrite Risk:
image-formats:generate command appends to image-formats.xml. If you manually edit the file, conflicts may arise.image-formats.xml before running the command.Locale Handling in Renaming:
rename command uses --locale to normalize filenames (e.g., Ümlaut → Umlaut).--locale explicitly to avoid unexpected behavior.Dry-Run Limitations:
--dry-run flag shows what would change but doesn’t validate storage permissions.Circular Dependencies in Crops:
@2x formats have conflicting crops, the bundle prioritizes @2x as the source.me_format_options table for orphaned entries after sync.Event Listener Issues:
@2x sync fails, verify the MediaCropModifiedEvent is dispatched (Sulu 3.x default, still the case in 3.1).debug:event-dispatcher to confirm event firing.Command Errors:
image-formats:generate, ensure YAML is valid (use symfony/validator for testing).--target=/tmp/test.xml to debug output before committing.Dependency Conflicts:
composer show alengo/sulu-media-extra-bundle and composer why sulu/sulu when the bundle won't install on a mixed-version stack.Custom Format Keys:
@2x suffixes. To support other variants (e.g., @3x), extend the MediaCropModifiedSubscriber:
// src/EventSubscriber/CustomCropSubscriber.php
use Alengo\SuluMediaExtraBundle\EventSubscriber\MediaCropModifiedSubscriber;
class CustomCropSubscriber extends MediaCropModifiedSubscriber {
protected function getBaseFormatKey(string $formatKey): ?string {
if (str_ends_with($formatKey, '@3x')) {
return str_replace('@3x', '', $formatKey);
}
return parent::getBaseFormatKey($formatKey);
}
}
services.yaml:
Alengo\SuluMediaExtraBundle\EventSubscriber\MediaCropModifiedSubscriber:
tags: [kernel.event_subscriber]
arguments:
$subscriber: '@custom_crop_subscriber'
Pre-Rename Validation:
MediaRenameCommand to add custom logic (e.g., blacklist filenames):
// src/Command/CustomMediaRenameCommand.php
use Alengo\SuluMediaExtraBundle\Command\MediaRenameCommand;
class CustomMediaRenameCommand extends MediaRenameCommand {
protected function execute(InputInterface $input, OutputInterface $output): int {
$newName = $input->getArgument('newName');
if (str_contains($newName, 'blocked')) {
$output->writeln('<error>Filename blocked!</error>');
return Command::FAILURE;
}
return parent::execute($input, $output);
}
}
Storage Path Customization:
rename command uses Sulu’s default storage adapter. To support custom paths (e.g., S3), extend the MediaRenamer service:
// src/Service/CustomMediaRenamer.php
use Alengo\SuluMediaExtraBundle\Service\MediaRenamer;
class CustomMediaRenamer extends MediaRenamer {
public function rename(Media $media, string $newName, string $locale): void {
// Add custom logic (e.g., S3 path handling)
parent::rename($media, $newName, $locale);
}
}
services.yaml:
Alengo\SuluMediaExtraBundle\Service\MediaRenamer:
class: App\Service\CustomMediaRenamer
How can I help you explore Laravel packages today?