alengo/sulu-media-extra-bundle
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).@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.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).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.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?