alengo/block-settings-bundle
Install the package:
composer require alengo/block-settings-bundle
Enable the bundle in config/bundles.php:
Alengo\SuluBlockSettingsBundle\BlockSettingsBundle::class => ['all' => true],
Configure sections in config/packages/alengo_block_settings.yaml:
alengo_block_settings:
sections:
- content_block_settings_theme
- content_block_settings_spacing
Create XML forms for each section (e.g., config/forms/content_block_settings_theme.xml):
<form xmlns="...">
<key>content_block_settings_theme</key>
<properties>
<section name="theme">
<property name="template_theme" type="select">
<!-- Define options -->
</property>
</section>
</properties>
</form>
Extend a block's settings with a theme selector and spacing controls without writing custom FormMetadataVisitor classes. The bundle injects these sections into the content_block_settings form automatically.
Define the XML form (e.g., content_block_settings_background.xml) with properties like:
<property name="background_color" type="color" />
<property name="background_image" type="media" />
Add the section key to alengo_block_settings.yaml:
alengo_block_settings:
sections:
- content_block_settings_theme
- content_block_settings_background # New section
Clear cache to apply changes:
php bin/console cache:clear
Dynamic block types: Use the bundle to inject settings for custom block types (e.g., custom_block_settings).
alengo_block_settings:
form_key: custom_block_settings
sections:
- custom_block_settings_layout
Conditional injection: Leverage Sulu’s FormMetadataVisitor priority to override or extend existing settings.
sections. Reorder for UI consistency.Form Key Mismatch:
form_key in config doesn’t match the target form (e.g., content_block_settings), sections won’t inject.XmlFormMetadataLoader matches the bundle’s config.Duplicate Sections:
sections, the first occurrence is used.var_dump($form->getKey()) in a custom visitor.Cache Dependencies:
php bin/console cache:clear
Inspect injected forms: Override the visitor temporarily to log form structure:
// src/Admin/FormMetadataVisitor/CustomVisitor.php
public function visitFormMetadata(FormMetadata $formMetadata, FormMetadataVisitorContext $context) {
if ($formMetadata->getKey() === 'content_block_settings') {
var_dump($formMetadata->getProperties());
}
}
Check XML validation: Invalid XML (e.g., missing key or section tags) will cause silent failures. Validate with:
php bin/console debug:container Alengo\SuluBlockSettingsBundle\BlockSettingsFormMetadataVisitor
Custom Visitor Logic: Override the visitor to add dynamic behavior (e.g., skip sections based on block type):
# config/services.yaml
App\Admin\FormMetadataVisitor\CustomBlockSettingsVisitor:
tags:
- { name: sulu_admin.form_metadata_visitor, priority: -5 }
Dynamic Section Loading:
Load sections from a database or API by extending BlockSettingsFormMetadataVisitor:
public function visitFormMetadata(FormMetadata $formMetadata, FormMetadataVisitorContext $context) {
if ($formMetadata->getKey() === $this->formKey) {
$dynamicSections = $this->sectionLoader->loadDynamicSections();
foreach ($dynamicSections as $section) {
$this->loadSection($section, $formMetadata);
}
}
}
Form Metadata Hooks:
Use Symfony’s kernel.event_listener to modify forms before injection:
services:
App\EventListener\BlockSettingsFormListener:
tags:
- { name: kernel.event_listener, event: sulu_admin.form_metadata_loaded, method: onFormLoaded }
How can I help you explore Laravel packages today?