The attached patch is fixing the desribed bug:
$option_value = (string) $option_value;: This line explicitly casts $option_value to a string. This ensures that the key is treated as a string in subsequent operations, which is important for consistency, especially when the keys are integers or other types that need to be compared or processed as strings.
Ana Bozhilova → created an issue.
Hi,
Here is and a fix for this warning from patch 31
Deprecated function: Return type of Drupal\firebase\Entity\MessageData::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include()
Hi,
Install "google/cloud-firestore": "^0.1.0"
Hi,
I have installed the latest patch and updated my code accordingly. I have also inserted the JSON file into the module configuration. However, I encountered an issue:
Error: Class "Google\Auth\ApplicationDefaultCredentials" not found in Drupal\firebase\Service\FirebaseServiceBase->getHandler()
The code I am using before the changes:
$messageService = Drupal::service('firebase.message');
$messageService->setTopics($topic);
$messageService->setNotification([
'title' => $val['title'],
'body' => $val['body'],
// 'badge' => 1,
// 'icon' => 'optional-icon',
'sound' => 'default',
// 'click_action' => 'optional-action',
]);
$messageService->setData([
'type' => 'axp-content', // default 'axp-content'
'url' => $val['url'], // zb '/axp/node/13'
]);
$messageService->setOptions(['priority' => 'normal']);
try {
$messageService->send();
} catch (Exception $e) {
$error = 'Push-Message failed: ' . $val['title'] . ' - ' . $val['body'] . ' URL: ' . $val['url'] . ' Error: ' . $e->getMessage();
}
Below is the updated code I am using:
I have installed the latest patch . I have change my code to be
/** @var FirebaseMessageService $messageService */
$messageService = \Drupal::service('firebase.message');
$messageService->setTopics($topic);
// Notification
$notification = new Notification($val['title']);
$notification->setBody($val['body']);
// Message data
$messageData = MessageData::fromArray([
'type' => 'axp-content',
'url' => $val['url'],
]);
// Message
$message = new Message($notification);
$message->setData($messageData);
$messageService->setMessage($message);
// Android config
$android_config = new AndroidConfig();
$android_config->setPriority('normal');
$message->setAndroidConfig($android_config);
// Apple config
$apns_config = new ApnsConfig();
$apns_config->setHeaders(['apns-priority' => '5']);
$apns_config->setPayload([
'aps' => [
'mutable-content' => 1,
'content-available' => 1
]
]);
$message->setApnsConfig($apns_config);
try {
$messageService->sendToTopic();
} catch (Exception $e) {
$error = 'Push-Message failed: ' . $val['title'] . ' - ' . $val['body'] . ' URL: ' . $val['url'] . ' Error: ' . $e->getMessage();
}
if I use $result = $messageService->sendToTokens() i got another eror. -> The message should contain target!
Another message. : Deprecated function
: Return type of Drupal\firebase\Entity\MessageData::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in
Structure of json file
type
project_id
private_key_id
private_key
client_email
client_id
auth_uri
token_uri
auth_provider_x509_cert_url
client_x509_cert_url
universe_domain
Hi,
I have installed the latest patch and updated my code accordingly. I have also inserted the JSON file into the module configuration. However, I encountered an issue:
Error: Class "Google\Auth\ApplicationDefaultCredentials" not found in Drupal\firebase\Service\FirebaseServiceBase->getHandler()
Below is the updated code I am using:
<strong>I have installed the latest patch . </strong>
I have change my code to be :
/** @var FirebaseMessageService $messageService */
$messageService = \Drupal::service('firebase.message');
$messageService->setTopics($topic);
// Notification
$notification = new Notification($val['title']);
$notification->setBody($val['body']);
// Message data
$messageData = MessageData::fromArray([
'type' => 'axp-content',
'url' => $val['url'],
]);
// Message
$message = new Message($notification);
$message->setData($messageData);
$messageService->setMessage($message);
// Android config
$android_config = new AndroidConfig();
$android_config->setPriority('normal');
$message->setAndroidConfig($android_config);
// Apple config
$apns_config = new ApnsConfig();
$apns_config->setHeaders(['apns-priority' => '5']);
$apns_config->setPayload([
'aps' => [
'mutable-content' => 1,
'content-available' => 1
]
]);
$message->setApnsConfig($apns_config);
try {
$messageService->sendToTopic();
} catch (Exception $e) {
$error = 'Push-Message failed: ' . $val['title'] . ' - ' . $val['body'] . ' URL: ' . $val['url'] . ' Error: ' . $e->getMessage();
}