I am currently trying to write a small app which provides a custom calendar,
but after simply copying the code from the documentation I can not get it working.
Basically only used the app template, changed the Application.php:
public function register(IRegistrationContext $context): void {
$context->registerCalendarProvider(\OCA\MyApp\Backend\CalendarProvider::class);
}
And added a file lib/Backend/CalendarProvider.php
<?php
namespace OCA\MyApp\Backend;
use OCP\Calendar\ICalendarProvider;
use Psr\Log\LoggerInterface;
class CalendarProvider implements ICalendarProvider {
protected LoggerInterface $logger;
public function __construct(LoggerInterface $logger) {
$this->logger = $logger;
$this->logger->debug('Construct!');
}
public function getCalendars(string $principalUri, array $calendarUris = []): array {
$this->logger->debug('getCalendars', ['uri' => $principalUri]);
return [];
}
}
But neither the __contruct nor the getCalendars is ever called.
(Also added some logic to provide custom calendars, but not relevant here)
I tried to find any working example, but the only app I could find providing custom calendars was the deck app, but that uses a completely different approach (using sabre DAV extensions directly).
So my question is, has someone sucessfully wrote an app providing custom calendars using the ICalendarProvider API? Or am I missing something?
I just tried to debug this a bit in my dev environment. I was not able to get it working as described in the documentation. I will ask the DAV group about this as I will probably need a calendar soon.
The main part of what I get so far is that the documentation is misleading. There are the calendars registered in PHP and those within CalDAV/Sabre. The official Calendar app will only show the CalDAV ones. The CalDAV remote.php backend will most probably not show the PHP-based calendars as well.
The question is not, what your intention is related to the calendars, @susnux. There is at least a workaround. I fear this a combination of a bug and a feature request in fact:
The DAV/calendar backend seems not to work with the PHP-registered calendars (rendering the documentation misleading).
Once a calendar is registered I had problems to see it with the documented PHP methods (see my own calender registered). I will most probably build a test case repository. From there I might be able to file a bug report/feature request.
Sorry, that I cannot give you a better report. At least there is a workaround possible to be used.
I wsa busy these days like hell due to my day-to-day obligations. I will try to fix some of the open issues on my personal agenda soon. One part is to have a look at the calendar thing. So, long story short, I have not done much since the PR.
It looks like you’re on the right track with implementing ICalendarProvider, but if neither __construct nor getCalendars is being called, the issue might be related to registration or caching. Here are a few things to check:
Check App Registration – Ensure your app is correctly registered and enabled in Nextcloud. Sometimes, changes don’t take effect until the app is fully reloaded.
Clear Cache & Logs – Try clearing Nextcloud’s cache and checking logs for any errors that might indicate why the provider isn’t being recognized.
Verify Namespace & Autoloading – Ensure your namespace is correct and that the class is being loaded properly. Running occ app:enable myapp after making changes can help refresh the setup.
Use Dependency Injection Properly – If the provider depends on other services, make sure they are injected correctly in Application.php.
If you’re looking for additional insights on how to structure a calendar app, this guide might be helpful: https://www.cleveroad.com/blog/create-a-calendar-app/. It provides a broader perspective on calendar app development that could give you some ideas.