Weave 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

Contact Bundle Laravel Package

dywee/contact-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation Run:

    composer require dywee/contact-bundle
    

    Register the bundle in config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 3):

    new Dywee\ContactBundle\DyweeContactBundle(),
    
  2. Routing Add to config/routes.yaml (Symfony 4+) or app/config/routing.yml (Symfony 3):

    dywee_contact:
        resource: "@DyweeContactBundle/Controller/"
        type: annotation
        prefix: /
    
  3. First Use Case

    • Visit /contact (or your configured prefix) to see the default contact form.
    • Submit the form to trigger the default handling (e.g., email or storage in a database).

Implementation Patterns

Basic Workflow

  1. Frontend Integration Use the default Twig template (@DyweeContact/form.html.twig) or override it in your theme:

    {% extends 'base.html.twig' %}
    {% block body %}
        {{ render(controller('DyweeContactBundle:Default:form')) }}
    {% endblock %}
    
  2. Customizing Form Fields Extend the form via dependency injection. Override the ContactType in your bundle:

    # config/services.yaml
    Dywee\ContactBundle\Form\ContactType:
        tags: ['form.type']
    

    Then define a custom form class:

    namespace App\Form;
    
    use Dywee\ContactBundle\Form\ContactType as BaseContactType;
    
    class ContactType extends BaseContactType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            parent::buildForm($builder, $options);
            $builder->add('custom_field', TextType::class);
        }
    }
    
  3. Handling Submissions Override the DefaultController to customize submission logic:

    namespace App\Controller;
    
    use Dywee\ContactBundle\Controller\DefaultController as BaseDefaultController;
    
    class DefaultController extends BaseDefaultController
    {
        public function formAction(Request $request)
        {
            $form = $this->createForm(ContactType::class);
            $form->handleRequest($request);
    
            if ($form->isSubmitted() && $form->isValid()) {
                $data = $form->getData();
                // Custom logic (e.g., save to DB, send email)
                $this->addFlash('success', 'Message sent!');
            }
    
            return $this->render('@App/contact/form.html.twig', [
                'form' => $form->createView(),
            ]);
        }
    }
    
  4. Admin Integration (DyweeCoreBundle) If using DyweeCoreBundle, submissions are automatically listed in the admin panel. Customize via:

    # config/packages/dywee_core.yaml
    dywee_core:
        admin:
            contact:
                label: 'Contacts'
                icon: 'fas fa-envelope'
    

Gotchas and Tips

Pitfalls

  1. Missing DyweeCoreBundle Dependencies The bundle assumes DyweeCoreBundle for admin features. If not installed, admin routes will fail. Install it separately:

    composer require dywee/dywee-core-bundle
    
  2. Routing Conflicts The default prefix (/) may clash with other routes. Use a subpath:

    dywee_contact:
        prefix: /contact
    
  3. Form Validation Overrides Customizing the form type may break validation if not extended properly. Always call parent::buildForm():

    parent::buildForm($builder, $options); // Required!
    

Debugging

  • Check Controller Paths Ensure the Controller/ directory exists in the bundle (src/Controller/). If missing, the routes will 404.

  • Twig Template Not Found Override templates in templates/bundles/DyweeContact/ to avoid "template not found" errors.

Extension Points

  1. Custom Storage Override the ContactHandler service to change where submissions are stored (e.g., database, API):

    services:
        Dywee\ContactBundle\Handler\ContactHandler:
            class: App\Handler\CustomContactHandler
    
  2. Email Templates Customize email templates by overriding:

    @DyweeContact/Email/contact.html.twig
    
  3. CSRF Protection If using Symfony 4+, ensure _csrf_token is included in the form:

    {{ form_start(form, { attr: { 'data-csrf-token': app.request.csrfToken } } ) }}
    
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.
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums