PHP code example of willsprod / ux-fullcalendar

1. Go to this page and download the library: Download willsprod/ux-fullcalendar library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

willsprod / ux-fullcalendar example snippets


use WillsProd\UX\FullCalendar\Builder\CalendarBuilderInterface;

#[Route('/calendar', name: 'app_calendar')]
public function calendar(CalendarBuilderInterface $builder): Response
{
    $calendar = $builder->createCalendar("my-calendar");
    
    // Options configuration
    $calendar->setOptions([
        'initialView' => 'timeGridWeek',
        'events' => $this->generateUrl('api_events'),
        'locale' => 'fr',
        'editable' => true,
        'selectable' => true,
    ]);
    
    // Actions for drag & drop events
    $calendar->setEventActions([
        'eventDropUrl' => $this->generateUrl('app_event_drop'),
        'eventResizeUrl' => $this->generateUrl('app_event_resize')
    ]);
    
    return $this->render('calendar/index.html.twig', [
        'calendar' => $calendar
    ]);
}

#[Route('/api/events', name: 'api_events')]
public function getEvents(): JsonResponse
{
    return $this->json([
        [
            'id' => 1,
            'title' => 'Meeting',
            'start' => '2025-08-12T10:00:00',
            'end' => '2025-08-12T11:00:00',
        ],
        // ... other events
    ]);
}

// Default plugins : dayGrid, timeGrid, interaction
$calendar = $builder->createCalendar("advanced");

// Add plugins
$calendar->addPlugin('list');
$calendar->addPlugin('rrule');

// Or défine completely
$calendar->setEnabledPlugins(['dayGrid', 'timeGrid', 'list']);

// Check if a plugin is active
if ($calendar->hasPlugin('interaction')) {
    // Your specific configuration
}

#[Route('/event/drop', name: 'app_event_drop', methods: ['POST'])]
public function eventDrop(Request $request): JsonResponse
{
    $data = json_decode($request->getContent(), true);
    
    // Process the event move
    // $data['eventId'], $data['newStart'], $data['newEnd']
    
    return $this->json([
        'success' => true,
        'message' => 'Event successfully moved'
    ]);
}

#[Route('/event/resize', name: 'app_event_resize', methods: ['POST'])]
public function eventResize(Request $request): JsonResponse
{
    $data = json_decode($request->getContent(), true);
    
    // Process resizing
    // $data['eventId'], $data['newStart'], $data['newEnd']
    
    return $this->json([
        'success' => true,
        'message' => 'Event successfully resized'
    ]);
}

$calendar->setOptions([
    'initialView' => 'timeGridWeek',
    'headerToolbar' => [
        'left' => 'prev,next today',
        'center' => 'title',
        'right' => 'dayGridMonth,timeGridWeek,timeGridDay'
    ],
    'locale' => 'fr',
    'timeZone' => 'Europe/Paris',
    'slotMinTime' => '08:00:00',
    'slotMaxTime' => '20:00:00',
    'weekends' => true,
    'nowIndicator' => true,
    'height' => 'auto',
    'buttonText' => [
        'today' => "Aujourd'hui",
        'month' => 'Mois',
        'week' => 'Semaine',
        'day' => 'Jour',
    ]
]);