Skip to content

Instantly share code, notes, and snippets.

@markocupic
Last active August 7, 2021 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markocupic/b6b6edcac8d1b6bf496b24ccfc88d3ce to your computer and use it in GitHub Desktop.
Save markocupic/b6b6edcac8d1b6bf496b24ccfc88d3ce to your computer and use it in GitHub Desktop.
Use terminal42/contao-notification_center to send messages when using markocupic/calendar-event-booking-bundle. Store these two files in src/EventListener respectively in contao/config. The Hook will transform a file uuid to a file path. Thus the file will be attached to the notification.
<?php
// contao/config/config.php
// notification center
if (isset($GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['calendar-event-booking-bundle'])) {
$GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['calendar-event-booking-bundle']['booking-notification']['attachment_tokens'] = ['document'];
}
<?php
// src/EventListener/SendNotificationMessage.php
declare(strict_types=1);
namespace App\EventListener;
use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\FilesModel;
use NotificationCenter\Model\Message;
use NotificationCenter\Model\Gateway;
/**
* @Hook("sendNotificationMessage")
*/
class SendNotificationMessage
{
public function __invoke(Message $objMessage, array &$arrTokens, ?string $language, Gateway $objGatewayModel)
{
$intMessageId = 2; // assuming, that the id of your NC message is 2.
if ((int)$objMessage->id === $intMessageId) {
$objFiles = FilesModel::findByUuid($arrTokens['document']);
if (null !== $objFiles) {
// Convert uuid to file path relative to the document root.
$arrTokens['document'] = $objFiles->path;
}
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment