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

Calendar Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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
    
  2. Register the Bundle Add to AppKernel.php:

    new ADesigns\CalendarBundle\ADesignsCalendarBundle(),
    
  3. Configure Routing Add to app/config/routing.yml:

    adesigns_calendar:
      resource: "@ADesignsCalendarBundle/Resources/config/routing.xml"
    
  4. Publish Assets

    php app/console assets:install web
    
  5. 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 %}
    

Implementation Patterns

Event Loading via Event Listeners

The bundle uses event listeners to load events dynamically. To add events from your own bundle:

  1. 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'],
            ];
        }
    }
    
  2. Tag the Service In services.yml:

    services:
        my.calendar_event_listener:
            class: AppBundle\EventListener\MyCalendarEventListener
            tags:
                - { name: adesigns_calendar.event_listener }
    

Customizing Event Routes

Override the default event route (adesigns_calendar_events) by:

  1. Extending the Controller Create a custom controller extending ADesigns\CalendarBundle\Controller\CalendarController and override eventsAction().
  2. Update Routing Replace the route in routing.yml with your custom route.

Twig Integration

Use the bundle’s Twig extensions for dynamic calendar rendering:

{{ render(controller('ADesignsCalendarBundle:Calendar:calendar', {
    'id': 'my-calendar',
    'eventsRoute': 'my_custom_events_route'
})) }}

AJAX Event Handling

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);
}

Gotchas and Tips

Common Pitfalls

  1. FOSJsRouting Dependency

    • Forgetting to install FOSJsRoutingBundle will break AJAX event loading. Verify the route fos_js_routing_js exists.
  2. Asset Paths

    • After updating assets, clear the cache:
      php app/console cache:clear --env=prod
      
    • Ensure web/bundles/adesignscalendar/ exists post-install.
  3. Event Listener Priority

    • Listeners are executed in the order they are tagged. Use the priority option in tags to control execution order:
      tags:
          - { name: adesigns_calendar.event_listener, priority: 10 }
      
  4. Timezone Issues

    • FullCalendar expects ISO 8601 dates. Ensure your Doctrine entities return dates in this format:
      $event->getStart()->format('Y-m-d\TH:i:sP');
      
  5. CORS for AJAX If events are loaded from a different domain, configure CORS in your Symfony app or proxy requests via a controller.

Debugging Tips

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

Extension Points

  1. Custom Event Models Extend the ADesigns\CalendarBundle\Model\EventInterface to add custom fields (e.g., location, description).

  2. Override Templates Copy ADesignsCalendarBundle::calendar.html.twig to AppBundle/Resources/views/ADesignsCalendarBundle/calendar.html.twig for customization.

  3. 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);
    }
    
  4. 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>
    
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity