public function AcsfThemeNotify::sendNotification in Acquia Cloud Site Factory Connector 8
Same name and namespace in other branches
- 8.2 src/AcsfThemeNotify.php \Drupal\acsf\AcsfThemeNotify::sendNotification()
Sends a theme notification to the Factory.
This is going to contact the Factory, so it qualifies as a third-party call, therefore calling it during a normal page load is not advisable. A possibly safer solution could be executing this via a menu callback called through an asynchronous JavaScript call.
If the request does not succeed (and $store_failed_notification is truthy), the notification will be stored so that we may try again later when cron runs.
Parameters
string $scope: The scope. Either "theme", "site", "group", or "global".
string $event_type: The type of theme event that occurred. Either "create", "modify", or "delete".
int $nid: The node ID associated with the scope. Only required for "group" scope notifications. If empty, it will be filled in automatically for "theme" and "site" scope notifications.
string $theme: The system name of the theme the event relates to. Only relevant for "theme" scope notifications.
int $timestamp: The timestamp when the notification was created.
bool $store_failed_notification: (optional) If TRUE, disable storing a notification when the sending fails. Should be only used in case of notifications which have been already added to the pending notification table.
Return value
array The message response body and code.
1 call to AcsfThemeNotify::sendNotification()
- AcsfThemeNotify::processNotifications in src/
AcsfThemeNotify.php - Resends failed theme notifications.
File
- src/
AcsfThemeNotify.php, line 79
Class
- AcsfThemeNotify
- Manages theme notifications that need to be sent to the Factory.
Namespace
Drupal\acsfCode
public function sendNotification($scope, $event_type, $nid = NULL, $theme = NULL, $timestamp = NULL, $store_failed_notification = TRUE) {
if (!$this
->isEnabled()) {
return [
'code' => 500,
'data' => [
'message' => $this
->t('The theme change notification feature is not enabled.'),
],
];
}
try {
if (empty($nid) && in_array($scope, [
'theme',
'site',
])) {
$site = AcsfSite::load();
$nid = $site->site_id;
}
$parameters = [
'scope' => $scope,
'event' => $event_type,
'nid' => $nid,
];
if ($theme) {
$parameters['theme'] = $theme;
}
if ($timestamp) {
$parameters['timestamp'] = $timestamp;
}
$message = new AcsfMessageRest('POST', 'site-api/v1/theme/notification', $parameters);
$message
->send();
$response = [
'code' => $message
->getResponseCode(),
'data' => $message
->getResponseBody(),
];
} catch (\Exception $e) {
$error_message = $this
->t('AcsfThemeNotify failed with error: @message.', [
'@message' => $e
->getMessage(),
]);
syslog(LOG_ERR, $error_message);
// Send a log message to the Factory.
$acsf_log = new AcsfLog();
$acsf_log
->log('theme_notify', $error_message, LOG_ERR);
$response = [
'code' => 500,
'data' => [
'message' => $error_message,
],
];
}
if ($store_failed_notification && $response['code'] !== 200) {
$this
->addNotification($event_type, $theme);
}
return $response;
}