Skip to content

Customize calendar

By default, the Calendar displays scheduled events of the following types:

  • Content publication (future_publication)
  • Content hide (future_hide)
  • Block reveal (page_block_reveal)
  • Block hide (page_block_hide)

You can perform basic actions on these events.

You can also configure the calendar to display custom event types.

Customize colors and icons

You can change the color of a calendar event or change the icon of an action. The setting is SiteAccess-aware.

To customize the appearance settings, add the following configuration:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ezplatform:
    system:
        admin_group:
            calendar:
                event_types:
                    future_publication:
                        color: '#47BEDB'
                        actions:
                            reschedule:
                                icon: '/bundles/ibexaplatformicons/img/all-icons.svg#notice'

Line 6 contains the name of the event type, either a built-in custom one.

color defines the color in which events of this type are displayed in the calendar. icon is the icon used for a button with the relevant event action.

Bank holiday with custom color

Configure custom events

The following example shows how to create custom events which add different holidays to the calendar.

First, create a new event in src/Calendar/Holidays/Event.php:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<?php declare(strict_types=1);

namespace App\Calendar\Holidays;

use DateTimeInterface;
use EzSystems\EzPlatformCalendar\Calendar\Event as CalendarEvent;

class Event extends CalendarEvent
{
    public function __construct(string $id, DateTimeInterface $dateTime, EventType $type)
    {
        parent::__construct($type, $id, $dateTime);
    }
}

Here, you define a new class for your event based on EzSystems\EzPlatformCalendar\Calendar\Event.

Next, create src/Calendar/Holidays/EventType.php:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php declare(strict_types=1);

namespace App\Calendar\Holidays;

use EzSystems\EzPlatformCalendar\Calendar\Event;
use EzSystems\EzPlatformCalendar\Calendar\EventAction\EventActionCollection;
use EzSystems\EzPlatformCalendar\Calendar\EventType\EventTypeInterface;

class EventType implements EventTypeInterface
{
    private const EVENT_TYPE_IDENTIFIER = 'holiday';

    private $actions;

    public function __construct(iterable $actions)
    {
        $this->actions = new EventActionCollection($actions);
    }

    public function getTypeIdentifier(): string
    {
        return self::EVENT_TYPE_IDENTIFIER;
    }

    public function getTypeLabel(): string
    {
        return 'Holidays';
    }

    public function getEventName(Event $event): string
    {
        return $event->getId();
    }

    public function getActions(): EventActionCollection
    {
        return $this->actions;
    }
}

You can use the identifier defined in lines 20-23 to configure event colors.

Complete the procedure by registering the new event type as a service:

1
2
3
4
5
6
services:
    App\Calendar\Holidays\EventType:
        arguments:
            $actions: [ ]
        tags:
            - { name: ezplatform.calendar.event_type }

Configure event sources

To add specific events to your calendar, you need to create an event source.

An event source must implement EzSystems\EzPlatformCalendar\Calendar\EventSource\EventSourceInterface.

One such built-in implementation is InMemoryEventSource. To add an in-memory collection as an event source, create src/Calendar/Holidays/EventSourceFactory.php:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php declare(strict_types=1);

namespace App\Calendar\Holidays;

use DateTime;
use DateTimeInterface;
use EzSystems\EzPlatformCalendar\Calendar\EventCollection;
use EzSystems\EzPlatformCalendar\Calendar\EventSource\EventSourceInterface;
use EzSystems\EzPlatformCalendar\Calendar\EventSource\InMemoryEventSource;

class EventSourceFactory
{
    private $eventType;

    public function __construct(EventType $eventType)
    {
        $this->eventType = $eventType;
    }

    public function createEventSource(): EventSourceInterface
    {
        $eventCollectionArray = [];
        $eventCollectionArray[] = $this->createEvent('April Fools', new DateTime('2022-04-01'));
        $collection = new EventCollection($eventCollectionArray);

        return new InMemoryEventSource($collection);
    }

    private function createEvent(string $id, DateTimeInterface $dateTime): Event
    {
        return new Event($id, $dateTime, $this->eventType);
    }
}

Note

When creating the list of events, you must list all the createEvent() entities chronologically.

For example:

1
2
3
4
$collection = new EventCollection([
    $this->createEvent("Event 1", new DateTime("2020-01-01")),
    $this->createEvent("Event 2", new DateTime("2020-01-02")),
    // ...

Next, register the event source as a service:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
services:
    App\Calendar\Holidays\EventSourceFactory:
        arguments:
            $eventType: '@App\Calendar\Holidays\EventType'

    App\Calendar\Holidays\EventSource:
        class: EzSystems\EzPlatformCalendar\Calendar\EventSource\InMemoryEventSource
        factory: [ '@App\Calendar\Holidays\EventSourceFactory','createEventSource' ]
        tags:
            - { name: ezplatform.calendar.event_source }

Now you can go to the Calendar tab and see the configured holiday.

Custom events list view

Import events from external sources

You can also import events from external sources, for example, a JSON file. To do this, place the following holidays.json file in src/Calendar/Holidays:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[
  {
    "date": "2022-01-01",
    "name": "New Year Day"
  },
  {
    "date": "2021-12-25",
    "name": "Christmas Day"
  }
]

Next, import this file in src/Calendar/Holidays/EventSourceFactory.php:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
    public function createEventSource(): EventSourceInterface
    {
        $eventCollectionArray = [];
        $eventCollectionArray[] = $this->createEvent('April Fools', new DateTime('2022-04-01'));

        $items = json_decode(file_get_contents(__DIR__ . \DIRECTORY_SEPARATOR . 'holidays.json'), true);
        foreach ($items as $item) {
            $eventCollectionArray[] = $this->createEvent($item['name'], new DateTime($item['date']));
        }

        $collection = new EventCollection($eventCollectionArray);

        return new InMemoryEventSource($collection);
    }

The calendar now displays the events listed in the JSON file.