Installation:
composer require dgarden/solid-bundle
Ensure SonataAdminBundle is already installed and configured.
Enable the Bundle:
Add to config/bundles.php:
Dgarden\SolidBundle\DgardenSolidBundle::class => ['all' => true],
First Use Case:
Annotate a Sonata Admin class with @Solid attributes to override default behaviors:
use Dgarden\SolidBundle\Annotation\Solid;
/**
* @Solid(
* list="custom_list", // Override list template
* edit="custom_edit" // Override edit template
* )
*/
class PostAdmin extends AbstractAdmin
{
// ...
}
Key Files:
src/Annotation/Solid.php: Attribute definitions.Resources/config/services.yaml: Bundle services (check for overrides).Resources/views/: Default templates (extend/modify these).Template Overrides:
Use @Solid to replace Sonata’s default templates (e.g., list, edit, show).
/**
* @Solid(list="AppBundle:Admin/post_list.html.twig")
*/
class PostAdmin extends AbstractAdmin {}
Dynamic Configuration:
Combine with Sonata’s configure*() methods for runtime logic:
public function configureListFields(ListMapper $listMapper)
{
$listMapper->add('title');
// Override via @Solid if needed
}
Field-Specific Attributes:
Override individual fields (e.g., edit, filter, form):
/**
* @Solid(
* fields={
* "title"={"edit"="custom_title_edit"}
* }
* )
*/
Integration with Twig:
Extend base templates in templates/admin/:
{# app/Resources/views/Admin/post_list.html.twig #}
{% extends '@DgardenSolid/CRUD/list.html.twig' %}
AppBundle:Admin/post_*).php bin/console cache:clear
phpunit to validate attribute parsing (check tests/ for examples).Attribute Parsing:
annotations is enabled in framework.yaml:
framework:
annotations: true
php bin/console debug:container dgarden.solid.attribute_reader to verify service registration.Template Priority:
@Solid overrides take precedence over Sonata’s defaults but not explicit configure*() methods.prependView() or appendView() in configureListFields() for hybrid approaches.GitFlow Quirks:
develop if not rebased. Prefer git merge --no-ff for clarity.Missing Documentation:
batch_actions). Inspect src/Annotation/Solid.php for all options.Attribute Not Applied?
Check if the admin class is properly scanned. Add a dump() in a compiler pass:
// src/DependencyInjection/Compiler/SolidPass.php
public function process(ContainerBuilder $container) {
$admins = $container->findTaggedServiceIds('sonata.admin');
dump(array_keys($admins)); // Verify your admin is tagged
}
Template Not Found?
Ensure the template path is correct (use absolute paths like AppBundle:Admin/post_list.html.twig).
Custom Attributes:
Extend Solid annotation by creating a subclass:
#[Attribute(Attribute::TARGET_CLASS)]
class CustomSolid extends Solid {}
Compiler Passes:
Override the bundle’s compiler pass in config/packages/dgarden_solid.yaml:
dgarden_solid:
compiler_passes:
- App\Custom\SolidPass
Event Subscribers:
Listen to sonata.admin.event.configure to dynamically modify attributes:
public static function getSubscribedEvents()
{
return [
'sonata.admin.event.configure' => 'onConfigure',
];
}
How can I help you explore Laravel packages today?