Installation
composer require dacorp/extra-bundle
Ensure compatibility with your Symfony version (master branch for Symfony 5+ or 1.0 branch for Symfony 2.1–2.3).
Enable the Bundle
Add to config/bundles.php:
return [
// ...
Dacorp\ExtraBundle\DacorpExtraBundle::class => ['all' => true],
];
First Use Case: Image Upload
Media entity (or extend an existing one) with fields for file paths.{% include "DacorpExtraBundle:Common:file-upload-control.html.twig" %}
punkave_image_uploader in config/packages/dacorp_extra.yaml (if using the legacy uploader).Entity Setup
Extend your entity with traits or fields for file storage (e.g., path, alt, mimeType).
Example:
use Dacorp\ExtraBundle\Model\MediaTrait;
class Product {
use MediaTrait;
}
Form Integration Use the provided Twig snippet in your form type:
$builder->add('image', FileType::class, [
'mapped' => false,
'template' => '@DacorpExtraBundle/Common/file-upload-control.html.twig',
]);
Handling Uploads
Inject the ImageUploaderService to process files:
public function __construct(private ImageUploaderService $uploader) {}
public function uploadImage(File $file, string $entity): string {
return $this->uploader->upload($file, $entity);
}
Twig Extension
Use the dacorp_extra.twig.meta extension in templates:
{% set meta = {
'title': 'Page Title',
'description': 'Meta description',
'twitter_card': 'summary_large_image',
'og_image': 'path/to/image.jpg'
} %}
{{ dacorp_extra.twig.meta(meta) }}
Dynamic Meta Data Pass variables from controllers:
return $this->render('page.html.twig', [
'meta' => [
'og_title' => $product->getName(),
'twitter_site' => '@your_handle',
],
]);
Configuration
Define app-specific IDs in config/packages/dacorp_extra.yaml:
dacorp_extra:
facebook_app_id: '123456789'
twitter_widget_id: 'abc123'
Routing
Extend routes with language prefixes (e.g., /en/page, /fr/page) using the bundle’s LanguageAwareRouter.
KnpMenu Integration
Use the KnpMenuBuilder with the LanguageSwitcher action:
$menu->addChild('Languages', ['route' => 'language_switcher'])
->setAttribute('lang', 'en');
Handler Setup
Configure the LanguageSwitcherHandler in services:
services:
App\EventListener\LanguageSwitcherListener:
tags:
- { name: 'kernel.event_listener', event: 'kernel.request', method: 'onKernelRequest' }
Legacy Uploader Dependency
The bundle defaults to punkave_image_uploader, which is deprecated. Migrate to oneup/uploader-bundle by:
oneup_uploader.Symfony Version Mismatch
1.0 is for Symfony 2.1–2.3. Avoid mixing branches.README Rendering The README feature is dev-only. Exclude from production by:
# config/packages/dacorp_extra.yaml
dacorp_extra:
readme:
enabled: '%kernel.debug%'
Image Upload Issues
var/log/dev.log for ImageUploaderService errors.public/uploads/.Meta Tags Not Rendering
config/packages/twig.yaml for DacorpExtraBundle).facebook_app_id and twitter_widget_id in parameters.yml.Language Switcher Failing
LanguageSwitcherHandler is registered as a service.language_switcher).Custom Media Model
Extend MediaTrait to add fields like size or thumbnail:
use Dacorp\ExtraBundle\Model\MediaTrait;
class CustomMedia {
use MediaTrait;
#[ORM\Column]
private ?string $thumbnailPath = null;
}
Override Twig Templates
Copy file-upload-control.html.twig to templates/bundles/DacorpExtra/Common/ for customization.
Add New Meta Types
Extend the MetaTagExtension to support additional platforms (e.g., LinkedIn):
// src/Twig/Extension/CustomMetaExtension.php
class CustomMetaExtension extends \Dacorp\ExtraBundle\Twig\MetaTagExtension {
public function getLinkedInTags(array $meta): string {
// ...
}
}
Register it in services.yaml:
services:
App\Twig\Extension\CustomMetaExtension:
tags: ['twig.extension']
How can I help you explore Laravel packages today?