gales / maker-bundle
Generador de ABMs basado en Petkopara Crud Generator reutilizando código del Maker Bundle de Symfony
Requires
- php: ^8.2
- doctrine/doctrine-bundle: ^2.10
- doctrine/orm: ^2.17|^3.0
- gales-petkopara/multi-search-bundle: ^2.7.2
- pagerfanta/pagerfanta: ^3.0|^4.0
- phpoffice/phpspreadsheet: ^1.30.7 || ^5.10
- spiriitlabs/form-filter-bundle: ^12.0
- symfony/filesystem: ^6.3|^7.0
- symfony/finder: ^6.3|^7.0
- symfony/form: ^6.3|^7.0
- symfony/framework-bundle: ^6.3|^7.0
- symfony/maker-bundle: ^1.21
- symfony/security-bundle: ^6.3|^7.0
- symfony/security-csrf: ^6.3|^7.0
Requires (Dev)
- phpunit/phpunit: ^10.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- v3.0.0
- v2.4.0
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- v1.1.0
- v1.0.1
- v0.6.5
- v0.6.4
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.8
- v0.5.7
- v0.5.6
- v0.5.5
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.1.11
- v0.1.10
- v0.1.9
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-develop
This package is auto-updated.
Last update: 2026-11-13 15:42:25 UTC
README
A powerful Symfony CRUD generator bundle with pagination, filtering, Bootstrap v5.2 markup and many advanced features. It's simple to use and fully customizable.
Designed to bring back the functionality of PetkoparaCrudGeneratorBundle, but reusing the logic from Symfony's Maker Bundle.
📋 Requirements
- PHP: 8.2+
- Symfony: 6.3, 7.0+
- Doctrine ORM: 2.5+ or 3.0+
- PhpSpreadsheet:
phpoffice/phpspreadsheet1.30.7+ or 5.10+ (the Excel export of the generated services)
📦 Installation
Add the Bundle with composer:
composer require gales/maker-bundle:^0.1
Configure Twig to use Bootstrap 5 Form Theme:
# config/packages/twig.yaml twig: form_themes: ['bootstrap_5_layout.html.twig']
🔤 Font (Montserrat)
The bundle's layout (base.html.twig) no longer loads Montserrat from Google Fonts, so it does not depend on an external CDN.
crud.css declares font-family: "Montserrat", so the project must provide the font itself. For example, with
@fontsource/montserrat imported from the Webpack Encore entry point:
npm install @fontsource/montserrat
// assets/app.js import '@fontsource/montserrat/300.css'; import '@fontsource/montserrat/400.css'; import '@fontsource/montserrat/600.css'; import '@fontsource/montserrat/700.css'; import '@fontsource/montserrat/800.css';
Without it, the browser falls back to the system sans-serif font.
⚡ Usage
Run the command:
php bin/console gales:make:crud
Using parameters:
php bin/console gales:make:crud <EntityClassName> [filter-type] [base-template]
Example:
php bin/console gales:make:crud Product input base.html.twig php bin/console gales:make:crud Product input base.html.twig --roles=ROLE_REPORTE php bin/console gales:make:crud Product input base.html.twig --route-prefix=/admin
⚠️ Base template: always pass your project's own
The base-template argument should always be your project's layout (e.g. base.html.twig), which already loads Bootstrap 5, Font Awesome, flatpickr and jQuery through your build (for example Webpack Encore).
The bundle's own layout (bundles/GALesMaker/base.html.twig, the default of the interactive prompt) is only a reference: it still points to bundles/galesmaker/... assets (Bootstrap, Font Awesome, flatpickr, jQuery, Popper) that the bundle no longer ships since the Bootstrap 5 migration, so those requests return 404 and the pages render unstyled. Do not use it as the base template of a real CRUD.
📁 Generated Files
After selecting the Entity for which to generate the CRUD, the following files are created:
created: src/Service/<entity_name>CrudService.php (Auxiliary logic for CRUD functionality)
created: src/Controller/<entity_name>Controller.php (Controller with CRUD logic)
created: src/Form/<entity_name>Type.php (Form for entity creation/editing)
created: src/Form/<entity_name>(Full)FilterType.php (Listing filter)
created: templates/<entity_name>/edit.html.twig (Entity editing view)
created: templates/<entity_name>/index.html.twig (Entity listing view)
created: templates/<entity_name>/new.html.twig (New entity creation view)
created: templates/<entity_name>/show.html.twig (Entity data visualization view)
Running the command again on an existing CRUD
When a file the command is about to generate already exists (controller, form types, <entity_name>CrudService, views, Voter
and their tests), the command shows a yellow warning (<path> ya existe. Si lo reemplazás se pierde cualquier lógica previa…) and asks ¿Reemplazarlo? for each one. Answering yes replaces the file,
losing any logic it had; the default answer is no, which skips it (Omitido: <path> ya existe y no se sobrescribe.).
Missing files are always created and the command exits with status 0. With --no-interaction every existing file is skipped.
php bin/console gales:make:crud Product input base.html.twig --force
--force replaces every existing file without asking, after a yellow warning at the start. Use it only on a clean working tree
and review git diff afterwards: it also overwrites the controller's BULK_ACTIONS map (your own bulk action classes are not touched).
If the generation fails, the files that were about to be replaced are restored.
🔒 Access roles
A generated CRUD is only accessible to ROLE_ADMIN unless you choose other roles when generating it:
- Interactive: after the base template, the command asks for extra roles one at a time, with autocompletion. Press Enter on an empty answer to finish.
- Non interactive:
--roles=ROLE_REPORTE,ROLE_CONSULTA(or--rolesrepeated). With-nand no--roles, onlyROLE_ADMIN.--roles=(empty) skips the question.
Every role must start with ROLE_ and use only uppercase letters, digits and _. A role that the project does not define is
accepted with a warning.
The chosen roles are written in the generated Voter, which is the single place to change them later:
// src/Security/ProductVoter.php public const ROLES = [ 'ROLE_ADMIN', 'ROLE_REPORTE', ];
- The controller requires
ProductVoter::ACCEDERon the whole class (#[IsGranted]): listing, export, bulk actions and any action you add. newrequiresProductVoter::CREAR;show,editanddeletekeepVER,EDITARandELIMINARon the entity; bulk actions keep their attribute (ELIMINARfor delete).- By default every attribute grants access to any role in
ROLES(role hierarchy included). ChangevoteOnAttribute()for finer rules, for example a role that can list but not delete. - If the route ends up under a prefix protected by
access_control, that rule must also allow the chosen roles: the first matching rule wins.
Configuration
# config/packages/gales_maker.yaml gales_maker: crud: # Static method or constant that returns the roles offered with autocompletion (the array values are used). roles_source: 'App\Entity\User::getRolesDetalle' # Roles that always have access. Default: [ROLE_ADMIN] default_roles: [ROLE_ADMIN]
The suggestions are the roles from roles_source followed by the keys and values of security.role_hierarchy, without the
default roles, ROLE_USER (any authenticated user) and the impersonation roles. If roles_source cannot be read, the command warns and goes on.
🛣️ Route prefix
By default the controller route comes from the entity name: Solicitud -> /solicitud, NotaPedido -> /nota/pedido.
If the back office is protected by route prefix (for example access_control with ^/admin), generate the CRUD under it:
php bin/console gales:make:crud Solicitud input base.html.twig --route-prefix=/admin -n
# #[Route("/admin/solicitud")]
- The leading
/is optional and a trailing one is ignored:admin,/adminand/admin/are the same. Nested prefixes work (/backoffice/admin). - Allowed characters: letters, digits,
-,_,.,/and{}(for parameters such as/{_locale}/admin). Anything else stops the command before writing files. - The route name (
solicitud_index, ...) does not change, only the path. - The final route is shown in the last line of the command (
Next: Check your new CRUD by going to /admin/solicitud/). --route-prefix=(empty) forces no prefix, even if a default is configured.
To avoid passing it every time, set a default in the bundle configuration (--route-prefix overrides it):
# config/packages/gales_maker.yaml gales_maker: crud: # Default route prefix of generated CRUDs. Default: none route_prefix: '/admin'
Regenerating an existing CRUD with a different prefix replaces its controller only if you confirm (or use --force); the other files do not depend on the path.
🎯 Features
- ✅ Full CRUD Operations (Create, Read, Update, Delete)
- ✅ Pagination with configurable page size
- ✅ Advanced Filtering (input, select, date filters)
- ✅ Bootstrap 5.2 responsive design
- ✅ Multi-column Sorting with custom ordering
- ✅ Form Validation with Symfony constraints
- ✅ Service Layer for business logic separation
- ✅ Twig Templates with inheritance support
- ✅ Symfony 7 compatible
📦 Bulk actions
Every generated CRUD lets the user select rows and apply a bulk action. Actions are classes tagged with
gales_maker.bulk_action, and each controller declares which ones it exposes in an explicit map
(action name => Voter attribute that authorizes it):
private const BULK_ACTIONS = [ 'delete' => ProductVoter::ELIMINAR, ];
- There is no default action: a controller without
BULK_ACTIONSentries exposes none, and an action that is not in the map answers400. GALes\MakerBundle\Bulk\BulkActionRunnerruns the action: it sanitizes the ids, loads the entities, checks the Voter attribute on every entity of the batch before running anything (if one is denied the response is403and nothing is executed), and runs the action in a single transaction. The action must not callflush(): the runner's transaction does it.- The form carries a CSRF token (
bulk_<route_name>); a missing or wrong token only shows an error flash and executes nothing. It requiresframework.csrf_protectionenabled andsymfony/security-csrf. - Only entities with a single identifier are supported.
delete(DeleteBulkAction) ships with the bundle.
Adding your own bulk action
- Implement the action in the project (autoconfiguration adds the tag):
namespace App\Bulk; use GALes\MakerBundle\Bulk\BulkActionInterface; use GALes\MakerBundle\Bulk\BulkResult; final class RenombrarBulkAction implements BulkActionInterface { public function getName(): string { return 'renombrar'; } public function getLabel(): string { return 'RENOMBRAR'; } public function getConfirmMessage(): string { return '¿Renombrar los registros seleccionados?'; } public function supports(string $entityClass): bool { return Product::class === $entityClass; } public function execute(array $entities): BulkResult { foreach ($entities as $product) { $product->setName(strtoupper($product->getName())); } return new BulkResult(count($entities), 'Registros renombrados'); } }
- Add the constant to the Voter (
RENOMBRAR = 'product_renombrar'), include it insupports()andvoteOnAttribute(). - Register it in the controller map:
'renombrar' => ProductVoter::RENOMBRAR,.
--force overwrites BULK_ACTIONS with the original map; your action classes are not touched.
Upgrading from v2.1.0
BulkDeleteService and tests/Service/BulkDeleteServiceTest.php generated by v2.1.0 are no longer used.
You can delete them after regenerating the controllers.
📊 Excel export
The generated <entity_name>CrudService exports the filtered listing to .xlsx through
GALes\MakerBundle\Spreadsheet\Factory, a service of this bundle that is autowired like any other.
It wraps PhpOffice\PhpSpreadsheet\IOFactory and works with phpoffice/phpspreadsheet 1.30.7+ and 5.10+,
so each project decides when to move to PhpSpreadsheet 5.
Upgrading from 1.x (yectep/phpspreadsheet-bundle)
From 2.0 the bundle no longer depends on yectep/phpspreadsheet-bundle, which limits PhpSpreadsheet to the 1.x branch.
Factory keeps the same methods (createSpreadsheet, createWriter, createReader, createStreamedResponse),
so in code generated by 1.x it is enough to change the import:
-use Yectep\PhpSpreadsheetBundle\Factory; +use GALes\MakerBundle\Spreadsheet\Factory;
Then remove Yectep\PhpSpreadsheetBundle\PhpSpreadsheetBundle from config/bundles.php and
composer remove yectep/phpspreadsheet-bundle (unless you use it elsewhere). The row handling of the generated
exportXlsx(iterable $iterableResult) expects Query::toIterable() (entities, not [0 => entity] rows): Query::iterate() and
IterableResult no longer exist in Doctrine ORM 3.
🚀 Development and Local Testing Setup
Clone the bundle repository outside your project, for example from your project root:
mkdir ../00_Bundles
cd ../00_Bundles
git clone https://github.com/GALes/maker-bundle.git
Add the following repositories to your project's composer.json:
{
"repositories":[
{
"type": "path",
"url": "../00_Bundles/maker-bundle",
"options": {
"symlink": true
}
}
],
"minimum-stability": "dev",
"prefer-stable": true
}
Install the bundle with composer:
composer require gales/maker-bundle:*
Then run:
composer dump-autoload
🤝 Contributing
Contributions are welcome! External contributors: please open a Pull Request against develop.
Branches and integration (maintainers)
masteris the default branch: the latest published stable version (the one Packagist serves).developintegrates ongoing work.- Every change starts from an issue. Work on a local branch
<n>_<slug>created fromdevelop(for a hotfix:hotfix/<n>_<slug>frommaster). Work branches are not pushed to origin. - To integrate: update the branch with
develop, run the tests (vendor/bin/phpunit), thengit merge --no-ff <branch>intodevelopwithCloses #Nin the message, and push. CI runs ondevelop, and the issue is closed automatically. - To publish:
git merge --no-ff developintomasterwith the messageMerge branch 'develop' (release vX.Y.Z), create an annotated tagvX.Y.Zwith the release notes, andgit push --atomic origin master vX.Y.Z. The GitHub Release is created by a workflow and Packagist picks up the tag. - Versioning:
featbumps the minor version,fixthe patch, and a breaking change (!) the major. - Never merge
masterintodevelop: a hotfix made onmasteris cherry-picked intodevelop. - Merged branches left on origin are deleted automatically.
📄 License
This project is licensed under the MIT License.
Upgrading from v2.2
CRUDs generated before v2.3 check nothing in index and new: they depend on access_control. To protect one without regenerating it:
- In the Voter, add
ROLES,ACCEDERandCREARas in the generated template (src/Resources/skeleton/security/Voter.tpl.php): both attributes are supported only with anullsubject and vote with the roles inROLES. - In the controller, add
use Symfony\Component\Security\Http\Attribute\IsGranted;and#[IsGranted(ProductVoter::ACCEDER)]on the class. - In
new(), add$this->denyAccessUnlessGranted(ProductVoter::CREAR);as the first line.
Regenerating only the controller while keeping an old Voter stops the command before writing anything, with a message that names the missing constants.