Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Lap Type Bundle Laravel Package

beelab/lap-type-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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],
    ];
    
  2. 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).


Implementation Patterns

Common Workflows

  1. Basic Lap Tracking

    $builder->add('laps', LapType::class, [
        'label' => 'Laps Completed',
        'attr' => ['min' => 0, 'max' => 100], // Optional constraints
    ]);
    
    • Useful for forms where users input discrete lap counts (e.g., cycling, swimming).
  2. 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]),
                ],
            ]);
        }
    }
    
  3. 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,
    ]);
    
  4. 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 %}
    

Gotchas and Tips

Pitfalls

  1. 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).

    • Workaround: Fork the repo if critical fixes are needed.
  2. 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).

    • Tip: Check the Form\Type\LapType.php source for defaults.
  3. 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;
    });
    

Debugging

  • Form Errors: Ensure min/max attributes align with your entity constraints to avoid validation conflicts.
  • Template Overrides: Clear the cache (php bin/console cache:clear) after theming changes.

Extension Points

  1. 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.

  2. 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]);
        }
    });
    
  3. Symfony 5+ Compatibility If using Symfony 5+, replace FormBuilderInterface with FormBuilder and update method signatures (e.g., add() now returns self).

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
babenkoivan/elastic-client
innmind/static-analysis
innmind/coding-standard
datacore/hub-sdk
alengo/sulu-http-cache-bundle
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php