Last active
August 7, 2021 21:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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']; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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