Installation:
composer require arkounay/block-bundle-i18n
Ensure your composer.json aligns with the package's Symfony 3.x constraints.
Enable Bundle:
Add to config/bundles.php:
Arkounay\BlockBundleI18n\BlockBundleI18n::class => ['all' => true],
Database Setup: Run migrations (if using Doctrine) to enable multilingual fields:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
First Use Case: Create a block entity with translatable content:
php bin/console make:entity Block
Add fields like content (type: text) and mark them for translation via A2lix\TranslationFormBundle annotations.
Block Creation & Management:
BlockManager to create, update, or fetch blocks:
$block = $blockManager->create('page_header', ['content' => 'Hello']);
$blockManager->save($block);
BlockManager into controllers/services via dependency injection.Multilingual Content Handling:
a2lix/translation-form-bundle for form translations:
{{ form_start(form) }}
{{ form_row(form.content) }} {# Translatable field #}
{{ form_end(form) }}
$content = $block->getTranslation('content', 'en');
TinyMCE Integration:
{{ block('tinymce') }}
config/packages/arkounay_block_i18n.yaml:
arkounay_block_i18n:
tinymce:
toolbar: bold italic | link unlink
Inline Editing:
{# Render block with editable content #}
{{ block_content(block, { editable: true }) }}
BlockType to customize block fields:
class CustomBlockType extends AbstractBlockType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('custom_field', TextType::class);
}
}
BlockEvents::PRE_SAVE) for pre-processing:
$eventDispatcher->addListener(BlockEvents::PRE_SAVE, function (BlockEvent $event) {
$block = $event->getBlock();
// Sanitize or modify block data
});
Locale Mismatches:
a2lix/translation-form-bundle is configured with supported locales in config/packages/a2lix_translation_form.yaml:
a2lix_translation_form:
default_locale: en
supported_locales: [en, fr, es]
php bin/console cache:clear
TinyMCE Assets Not Loading:
assets/install was run post-installation:
php bin/console assets:install
Doctrine Behaviors Conflicts:
knplabs/doctrine-behaviors for timestamps. Ensure no duplicate behaviors are applied to the same entity.Deprecated Symfony 3.x:
AbstractController). Stick to Symfony 3.x patterns.if (!$blockManager->exists('page_header', ['id' => 123])) {
throw new \RuntimeException('Block not found');
}
# config/packages/dev/arkounay_block_i18n.yaml
arkounay_block_i18n:
debug: true
Block and register them via services:
services:
App\Entity\CustomBlock:
tags: ['arkounay.block.type']
vendor/arkounay/block-bundle-i18n/Resources/views/ to templates/arkounay_block_i18n/ to customize rendering.BlockValidator to add custom rules:
class CustomBlockValidator extends BlockValidator {
public function validate($block, Constraint $constraint) {
// Custom logic
}
}
Register it in services.yaml:
services:
App\Validator\CustomBlockValidator:
tags: ['validator.constraint_validator']
```markdown
### Configuration Quirks
- **Default Locale Fallback**: The bundle defaults to `en` if no locale is specified. Override in `config/packages/arkounay_block_i18n.yaml`:
```yaml
arkounay_block_i18n:
default_locale: fr
block_translation). Ensure your Doctrine schema reflects this.How can I help you explore Laravel packages today?