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(),
Routing
Add to config/routes.yaml (Symfony 4+) or app/config/routing.yml (Symfony 3):
dywee_contact:
resource: "@DyweeContactBundle/Controller/"
type: annotation
prefix: /
First Use Case
/contact (or your configured prefix) to see the default contact form.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 %}
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);
}
}
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(),
]);
}
}
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'
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
Routing Conflicts
The default prefix (/) may clash with other routes. Use a subpath:
dywee_contact:
prefix: /contact
Form Validation Overrides
Customizing the form type may break validation if not extended properly. Always call parent::buildForm():
parent::buildForm($builder, $options); // Required!
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.
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
Email Templates Customize email templates by overriding:
@DyweeContact/Email/contact.html.twig
CSRF Protection
If using Symfony 4+, ensure _csrf_token is included in the form:
{{ form_start(form, { attr: { 'data-csrf-token': app.request.csrfToken } } ) }}
How can I help you explore Laravel packages today?