Installation Add the bundle to your project via Composer:
composer require beelab/lap-type-bundle
Register the bundle in config/bundles.php:
return [
// ...
BeeLab\LapTypeBundle\BeeLabLapTypeBundle::class => ['all' => true],
];
First Use Case
Use the LapType in a Symfony form builder:
use BeeLab\LapTypeBundle\Form\Type\LapType;
$builder->add('lap', LapType::class);
This renders a lap counter input (e.g., for race tracking, fitness apps, or time-based metrics).
Basic Lap Tracking
$builder->add('laps', LapType::class, [
'label' => 'Laps Completed',
'attr' => ['min' => 0, 'max' => 100], // Optional constraints
]);
Dynamic Lap Validation Extend the type to add custom validation:
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class CustomLapType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('laps', LapType::class, [
'constraints' => [
new NotBlank(),
new Range(['min' => 1, 'max' => 50]),
],
]);
}
}
Integration with Entities
Map the LapType to a Doctrine entity field:
#[ORM\Entity]
class RaceEntry {
#[ORM\Column(type: 'integer')]
private ?int $lapCount = null;
// Getters/setters...
}
$builder->add('lapCount', LapType::class, [
'mapped' => true,
'data_class' => RaceEntry::class,
]);
Theming
Override the default template in templates/BeeLabLapTypeBundle/form/fields.html.twig:
{% block lap_widget %}
<input type="number" {{ block('widget_attributes') }} class="lap-input" />
{% endblock %}
Archived Status The package is archived (no active maintenance). Verify compatibility with your Symfony version (tested on Symfony 3.x/4.x in the README).
Limited Documentation
The Resources/doc/index.md may lack depth. Expect minimal built-in features (e.g., no built-in step increments or custom icons).
Form\Type\LapType.php source for defaults.No Built-in JavaScript
The type renders a basic <input type="number">. For advanced UX (e.g., buttons to increment laps), add custom JS:
document.querySelector('.lap-input').addEventListener('change', (e) => {
if (e.target.value < 0) e.target.value = 0;
});
min/max attributes align with your entity constraints to avoid validation conflicts.php bin/console cache:clear) after theming changes.Custom Data Transformers Convert between raw input (e.g., string) and entity values:
use Symfony\Component\Form\DataTransformerInterface;
class LapStringToIntTransformer implements DataTransformerInterface {
public function transform($value) {
return (int) $value;
}
public function reverseTransform($value) {
return strval($value);
}
}
Register it in the form type.
Event Subscribers
Listen to form events (e.g., PRE_SET_DATA) to modify lap values dynamically:
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$data = $event->getData();
if ($data && $data->getLaps() > 100) {
$event->setData((object) ['laps' => 100]);
}
});
Symfony 5+ Compatibility
If using Symfony 5+, replace FormBuilderInterface with FormBuilder and update method signatures (e.g., add() now returns self).
How can I help you explore Laravel packages today?