Installation:
composer require 2lenet/crudit-bundle
npm install bootstrap@5 sass sass-loader @fortawesome/fontawesome-free easymde --save
Enable the Bundle:
Add to config/bundles.php:
return [
// ...
Lle\CruditBundle\LleCruditBundle::class => ['all' => true],
];
Basic Twig Integration:
Extend the provided layout in your base template (templates/base.html.twig):
{% extends '@LleCrudit/layout/sb_admin/layout.html.twig' %}
{% block stylesheets %}
{{ encore_entry_link_tags('app') }}
{% endblock %}
{% block javascripts %}
{{ parent() }}
{{ encore_entry_script_tags('app') }}
{% endblock %}
First CRUD:
Follow the CRUD doc to scaffold a basic CRUD interface for an entity (e.g., App\Entity\Post):
php bin/console lle:crudit:generate Post
Generate a CRUD for a Product entity and customize the list view to display name, price, and createdAt:
php bin/console lle:crudit:generate Product
Then override the list template in templates/LleCrudit/Product/list.html.twig:
{% extends '@LleCrudit/Product/list.html.twig' %}
{% block table_headers %}
{{ parent() }}
<th>Price</th>
{% endblock %}
{% block table_rows %}
{{ parent() }}
<td>{{ product.price }}</td>
{% endblock %}
Scaffolding:
Use the lle:crudit:generate command to create CRUD interfaces for entities:
php bin/console lle:crudit:generate User --fields=name,email,roles --list=name,email,createdAt
--fields: Specify fields to include in the form.--list: Define columns for the list view.Customization:
Override default templates in templates/LleCrudit/[EntityName]/:
list.html.twig: Modify the table structure.edit.html.twig: Customize the form fields.show.html.twig: Adjust the detail view.Field Types:
Leverage built-in field types (e.g., text, number, boolean, association) or create custom ones by extending Lle\CruditBundle\Form\Type\AbstractType.
Filters:
Add filters to list views using the filters option in the CRUD configuration (see Filters doc):
# config/packages/lle_crudit.yaml
lle_crudit:
cruds:
App\Entity\Product:
list:
filters:
- { name: 'name', type: 'text' }
- { name: 'price', type: 'number' }
Menus:
Integrate CRUDs into the sidebar menu via the menu configuration:
lle_crudit:
menu:
- { route: 'lle_crudit_product_list', label: 'Products', icon: 'box' }
Bricks: Reuse UI components (e.g., cards, modals) by creating custom bricks (see Brick doc):
{% render_brick 'product_card', { product: product } %}
Webpack Encore:
Ensure app.js imports Crudit’s SCSS after your custom styles:
// assets/js/app.js
import '../styles/app.scss';
// assets/styles/app.scss
@import '../../vendor/le/crudit-bundle/assets/sb-admin/css/app.scss';
Security:
Protect CRUD routes with Symfony’s security system (e.g., @IsGranted("ROLE_ADMIN") in controllers).
Validation: Extend entity validation or use Crudit’s built-in validation by configuring field rules in the CRUD YAML:
lle_crudit:
cruds:
App\Entity\Product:
fields:
price:
validation: { notBlank: true, min: 0 }
API Integration:
Use Crudit for admin interfaces while keeping API endpoints separate (e.g., via Symfony’s ApiPlatform or custom controllers).
SCSS Order:
app.scss (as shown in the README).Webpack Encore Conflicts:
webpack.config.js to resolve dependencies:
// webpack.config.js
Encore.enableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.configureBabel((config) => {
config.plugins.push('@babel/plugin-proposal-class-properties');
})
.configureLoaderRule('sass', (rule) => {
rule.use.push({
loader: 'sass-loader',
options: { implementation: require('sass') }
});
});
Template Overrides:
{% block %} inheritance carefully. For example, to add a column:
{% block table_rows %}
{{ parent() }} {# Renders default rows #}
<td>{{ product.customField }}</td>
{% endblock %}
Entity Changes:
templates/LleCrudit/[EntityName]/ directory and regenerate:
rm -rf templates/LleCrudit/Product/
php bin/console lle:crudit:generate Product
Performance:
limit option in the CRUD config:
lle_crudit:
cruds:
App\Entity\Product:
list:
pagination: 20
Console Commands: List available CRUDs to verify configuration:
php bin/console lle:crudit:list
Template Debugging:
Enable Twig debug mode in .env:
APP_DEBUG=1
Use {{ dump(_context) }} in templates to inspect variables.
JavaScript Errors: Check the browser console for errors related to:
$primary).app.scss:
$primary: #your-color !default;
@import '../../vendor/le/crudit-bundle/assets/sb-admin/css/app.scss';
Custom Field Types:
Create reusable field types by extending AbstractType:
// src/Form/Type/CustomFieldType.php
namespace App\Form\Type;
use Lle\CruditBundle\Form\Type\AbstractType;
class CustomFieldType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('custom_field', TextType::class);
}
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults([
'label' => 'Custom Field',
]);
}
}
Register in config/packages/lle_crudit.yaml:
lle_crudit:
field_types:
custom: App\Form\Type\CustomFieldType
Event Listeners:
Hook into Crudit events (e.g., CruditEvent::PRE_LIST) to modify queries or data:
// src/EventListener/CruditListener.php
namespace App\EventListener;
use Lle\CruditBundle\Event\CruditEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CruditListener implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
CruditEvent::PRE_LIST => 'onPreList',
];
}
public function onPreList(CruditEvent $event) {
$event->getQueryBuilder()->andWhere('e.active = :active')
->setParameter('active', true);
}
}
Dynamic Routes:
Override routing for CRUD actions in config/routes.yaml:
lle
How can I help you explore Laravel packages today?