You are here

function _firebase_addOptionalFields in Firebase Push Notification (FCM) 7

Adds optional fields to payload.

Parameters

array $param: Data for payload.

Return value

array Optional payload.

1 call to _firebase_addOptionalFields()
_firebase_buildMessage in ./firebase.module
Builds the push notification body.

File

./firebase.module, line 211

Code

function _firebase_addOptionalFields($param) {
  $message = [];
  if (!empty($param['priority'])) {
    $message['priority'] = $param['priority'];
  }
  if (!empty($param['title']) && !empty($param['body'])) {
    $message['notification'] = [
      'title' => $param['title'],
      'body' => $param['body'],
    ];
  }

  // If an icon, sound or click_action are available,
  // add them to notification body.
  if (!empty($param['icon'])) {
    $message['notification']['icon'] = $param['icon'];
  }
  if (!empty($param['sound'])) {
    $message['notification']['sound'] = $param['sound'];
  }
  if (!empty($param['click_action'])) {
    $message['notification']['click_action'] = $param['click_action'];
  }
  if (!empty($param['content_available'])) {
    $message['content_available'] = $param['content_available'];
  }
  if (isset($param['badge'])) {
    $message['notification']['badge'] = $param['badge'];
  }

  // Data is not displayed to app users. It is usually used to send
  // some data to be processed by the app.
  if (!empty($param['data'])) {
    $message['data'] = $param['data'];
  }
  return $message;
}