adexerivera/calendar-bundle
Symfony2 bundle integrating jQuery FullCalendar. Loads events via AJAX and dispatches a calendar.load_events event so any bundle can supply events through listeners. Includes routes, assets, and a Twig include to render the calendar.
Install Dependencies
Ensure FOSJsRoutingBundle is installed and configured first:
composer require friendsofsymfony/jsrouting-bundle
Then install the bundle:
composer require adesigns/calendar-bundle:dev-master
Register the Bundle
Add to AppKernel.php:
new ADesigns\CalendarBundle\ADesignsCalendarBundle(),
Configure Routing
Add to app/config/routing.yml:
adesigns_calendar:
resource: "@ADesignsCalendarBundle/Resources/config/routing.xml"
Publish Assets
php app/console assets:install web
First Use Case Add FullCalendar to a Twig template:
{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="{{ asset('bundles/adesignscalendar/css/fullcalendar.css') }}">
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('bundles/adesignscalendar/js/fullcalendar.min.js') }}"></script>
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
events: Routing.generate('adesigns_calendar_events')
});
});
</script>
{% endblock %}
The bundle uses event listeners to load events dynamically. To add events from your own bundle:
Create an Event Listener
Implement ADesigns\CalendarBundle\Event\CalendarEventListenerInterface:
use ADesigns\CalendarBundle\Event\CalendarEventListenerInterface;
use ADesigns\CalendarBundle\Event\CalendarEvent;
class MyCalendarEventListener implements CalendarEventListenerInterface
{
public function getEvents(CalendarEvent $event)
{
return [
['title' => 'Meeting', 'start' => '2023-10-01', 'end' => '2023-10-02'],
];
}
}
Tag the Service
In services.yml:
services:
my.calendar_event_listener:
class: AppBundle\EventListener\MyCalendarEventListener
tags:
- { name: adesigns_calendar.event_listener }
Override the default event route (adesigns_calendar_events) by:
ADesigns\CalendarBundle\Controller\CalendarController and override eventsAction().routing.yml with your custom route.Use the bundle’s Twig extensions for dynamic calendar rendering:
{{ render(controller('ADesignsCalendarBundle:Calendar:calendar', {
'id': 'my-calendar',
'eventsRoute': 'my_custom_events_route'
})) }}
For CRUD operations, extend the eventsAction() to handle POST/PUT/DELETE requests:
public function eventsAction(Request $request)
{
$method = $request->getMethod();
if ($method === 'POST') {
// Handle event creation
} elseif ($method === 'PUT') {
// Handle event update
} elseif ($method === 'DELETE') {
// Handle event deletion
}
return $this->getEvents($request);
}
FOSJsRouting Dependency
FOSJsRoutingBundle will break AJAX event loading. Verify the route fos_js_routing_js exists.Asset Paths
php app/console cache:clear --env=prod
web/bundles/adesignscalendar/ exists post-install.Event Listener Priority
priority option in tags to control execution order:
tags:
- { name: adesigns_calendar.event_listener, priority: 10 }
Timezone Issues
$event->getStart()->format('Y-m-d\TH:i:sP');
CORS for AJAX If events are loaded from a different domain, configure CORS in your Symfony app or proxy requests via a controller.
Check Event Listener Execution Temporarily log events in your listener to verify data flow:
public function getEvents(CalendarEvent $event)
{
\Symfony\Component\Debug\Debug::dump($event->getRequest()->query);
return [...];
}
Validate Routes
Use php app/console router:debug to confirm adesigns_calendar_events is registered.
Inspect FullCalendar Console Open browser dev tools (Console tab) to check for FullCalendar errors or failed AJAX calls.
Custom Event Models
Extend the ADesigns\CalendarBundle\Model\EventInterface to add custom fields (e.g., location, description).
Override Templates
Copy ADesignsCalendarBundle::calendar.html.twig to AppBundle/Resources/views/ADesignsCalendarBundle/calendar.html.twig for customization.
Add Validation
Validate event data in a custom eventsAction() before processing:
$validator = $this->get('validator');
$errors = $validator->validate($eventData);
if (count($errors) > 0) {
return new Response(json_encode(['errors' => (string) $errors]), 400);
}
Localization Override FullCalendar’s language files by publishing the bundle’s translations:
php app/console assets:install web --symlink
Then link to your custom language file in Twig:
<script src="{{ asset('bundles/adesignscalendar/js/lang-all.js') }}"></script>
How can I help you explore Laravel packages today?