Installation Add the bundle via Composer:
composer require dotcommerce/fastentitybundle
Register the bundle in config/bundles.php:
return [
// ...
DotCommerce\FastEntityBundle\DotCommerceFastEntityBundle::class => ['all' => true],
];
Generate FastEntity Form Type
Run the generation command for a specific entity (e.g., Customer in StoreBundle with lastname as the dropdown field):
php bin/console dotcommerce:generate:fastentity StoreBundle:Customer lastname
This creates a new form type class (e.g., FastCustomerType) in StoreBundle/Form/FastCustomerType.php.
First Use Case Use the generated form type in a Symfony form builder:
use StoreBundle\Form\FastCustomerType;
$builder->add('customer', FastCustomerType::class);
Bulk Generation
Generate form types for all entities in a bundle (omitting EntityName):
php bin/console dotcommerce:generate:fastentity StoreBundle
Uses the name field by default if FieldName is omitted.
Dynamic Dropdowns Integrate with form events to dynamically update dropdowns (e.g., cascading selects):
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$form = $event->getForm();
$form->add('related_entity', FastRelatedEntityType::class);
});
Custom Querying Extend the generated form type to add custom query logic (e.g., filtering):
// StoreBundle/Form/FastCustomerType.php
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults([
'query_builder' => function (EntityManagerInterface $em) {
return $em->getRepository(Customer::class)
->createQueryBuilder('c')
->where('c.isActive = :active')
->setParameter('active', true);
},
]);
}
Reusing in Templates Use the form type in Twig templates with custom labels/options:
{{ form_row(form.customer, {
'label': 'Select Customer',
'attr': {'class': 'form-control'}
}) }}
Development Workflow: Regenerate form types during development if entity fields change:
php bin/console dotcommerce:generate:fastentity StoreBundle:Customer --force
(Note: --force is hypothetical; verify if supported.)
CI/CD Integration: Add the generation command to deployment scripts to ensure form types are up-to-date.
Symfony Forms:
Combine with other form types (e.g., EntityType for fallback):
$builder->add('customer', FastCustomerType::class, [
'required' => false,
'placeholder' => 'Select a customer...',
]);
API Platform: Use the bundle for admin interfaces while keeping API endpoints clean.
Doctrine Extensions:
Pair with StoDoctrineExtensionsBundle for soft-deleted entities:
// In FastCustomerType::configureOptions()
'query_builder' => function (EntityManagerInterface $em) {
return $em->getRepository(Customer::class)
->createQueryBuilder('c')
->where('c.deletedAt IS NULL');
}
Outdated Command Syntax: The bundle is abandoned (last update: 2012). Assumptions:
EntityType if the bundle fails.Namespace Conflicts:
Generated form types (e.g., FastCustomerType) may clash with existing classes. Prefix manually:
php bin/console dotcommerce:generate:fastentity StoreBundle:Customer lastname --prefix=Store
(Note: --prefix is hypothetical; verify or rename manually.)
Caching Issues: Clear cache after generation:
php bin/console cache:clear
Field Name Assumptions:
The bundle defaults to the name field if FieldName is omitted. Override in configureOptions() if needed:
$resolver->setDefaults([
'choice_label' => 'email', // Custom field
]);
Command Errors:
Check if the bundle’s DotCommerceFastEntityBundle is properly registered in bundles.php.
Verify the entity exists in the bundle’s Resources/config/doctrine/ directory.
Form Type Not Found:
Ensure the generated class (e.g., FastCustomerType) is autoloaded. Run:
composer dump-autoload
Query Builder Failures:
Debug with dd() in the generated form type’s configureOptions() to inspect the query.
Symfony 4+ Flex Compatibility:
Manually create the Form/ directory if missing:
mkdir -p src/StoreBundle/Form
Doctrine Metadata: The bundle relies on Doctrine’s metadata. Ensure entities are properly mapped:
php bin/console doctrine:schema:validate
Custom Form Type Logic: Extend the generated form type to add validation or custom choices:
public function getParent() {
return FastCustomerType::class; // Extend the generated type
}
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults([
'choices' => $this->getCustomChoices(),
]);
}
Dynamic Choice Loading:
Use choice_loader for lazy-loaded dropdowns (Symfony 4.3+):
$builder->add('customer', FastCustomerType::class, [
'choice_loader' => new CustomerLoader($em),
]);
Event Subscribers:
Listen to FormEvents::PRE_SET_DATA to modify form types dynamically:
$formModifier->modifyForm($builder, $data);
How can I help you explore Laravel packages today?