Developer Events & Hooks

If you wish to extend the capabilities of Calendar, you can use any of the events and hooks below:

Events for Calendar Events

\Solspace\Calendar\Services\EventsService

  • ::EVENT_BEFORE_SAVE #
    • Called before saving the event data
    • \Solspace\Calendar\Events\SaveElementEvent contains these methods:
      • getElement() - returns \Solspace\Calendar\Elements\Event
      • isNew() - bool
  • ::EVENT_AFTER_SAVE #
    • Called after saving the event data
    • \Solspace\Calendar\Events\SaveElementEvent contains these methods:
      • getElement() - returns \Solspace\Calendar\Elements\Event
      • isNew() - bool
  • ::EVENT_BEFORE_DELETE #
    • Called before deleting an event
    • \Solspace\Calendar\Events\DeleteElementEvent contains these methods:
      • getElement() - returns \Solspace\Calendar\Elements\Event
  • ::EVENT_AFTER_DELETE #
    • Called after deleting an event
    • \Solspace\Calendar\Events\DeleteElementEvent contains these methods:
      • getElement() - returns \Solspace\Calendar\Elements\Event

Events for Calendars

\Solspace\Calendar\Services\CalendarsService

  • ::EVENT_BEFORE_SAVE #
    • Called before saving the calendar data
    • \Solspace\Calendar\Events\SaveModelEvent contains these methods:
      • getModel() - returns \Solspace\Calendar\Models\CalendarModel
      • isNew() - bool
  • ::EVENT_AFTER_SAVE #
    • Called after saving the calendar data
    • \Solspace\Calendar\Events\SaveModelEvent contains these methods:
      • getModel() - returns \Solspace\Calendar\Models\CalendarModel
      • isNew() - bool
  • ::EVENT_BEFORE_DELETE #
    • Called before deleting a calendar
    • \Solspace\Calendar\Events\DeleteModelEvent contains these methods:
      • getModel() - returns \Solspace\Calendar\Models\CalendarModel
  • ::EVENT_AFTER_DELETE #
    • Called after deleting a calendar
    • \Solspace\Calendar\Events\DeleteModelEvent contains these methods:
      • getModel() - returns \Solspace\Calendar\Models\CalendarModel

Usage Examples

In your plugin's ::init() method, subscribe to any of these events by using the Event::on() static method:

<?php

namespace Your\Plugin\Namespace;

use Solspace\Calendar\Events\SaveElementEvent;

class YourPlugin extends BasePlugin
{
  public function init()
  {
    parent::init();

    // Forms
    Event::on(
      EventsService::class,
      EventsService::EVENT_BEFORE_SAVE,
      function (SaveElementEvent $event) {
        $event = $event->getElement();
        $isNew = $event->isNew();
        // Do something with this data
      }
    );
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Last Updated: 1/14/2019, 4:12:52 PM