Drupal Push Notification

Sending Push Notification in Drupal with your plugin

It is difficult to implement even simple features in Drupal. Luckily Drupal is one of the CMS which have the largest number of plugins (modules). For implementing push notification feature, there are some good plugins available. We are selecting one plugin from the module gallery and will try to implement the push notification feature for our custom developed module.

Drupal’s “Push Notifications” Module

The module “Push Notifications” will help us to do the push notifications and device registrations for us. You can find and download the module at Drupal website. The module supports:

  1. Apple Push Notification Service (APNS)
  2. Google Cloud Messaging (GCM) and
  3. Cloud 2 Device Messaging (C2DM).

 How to Implement Push Notification Module?

Login to your admin panel and install your module. Follow the steps given below:

  1. Login to your admin panel.
  2. Go to your admin page: http://yoursite.com/?q=admin/modules/install
  3. In the field “Install from a URL”, use the following URL: http://ftp.drupal.org/files/projects/push_notifications-7.x-1.1.tar.gz (you can find the latest version from the module page).
  4. Click on “Install” button.
  5. If everything works fine, you will get a message like “Installation was completed successfully.”
  6. Click on the “Enable newly added modules” link to go to the modules listing page.
  7. Go down to the page to see the “Push Notifications” plugins under “Others” category.
  8. Check the enabled column and save the configurations. Your push notification module is enabled now.
  9. Add the certificates and key in the page: Configuration > Web Serivces > Push Notifications > Configuration. For APNS certificate, click on “Generate new certificate string” button, rename your certificates to the displayed names and upload to the sites/all/modules/push_notifications/certificates folder.
  10. After saving your settings, you can test messages to the registered devices from “Send Push” tab.

Configure your module to add the dependency

Since your module is going to use push_notifications module, you have to add dependency for the module. The push_notifications module itself is dependent to the  services, so your module is dependent to both services and push_notifications. After adding dependency, your module info file will look like:

Send Push Notifications from your custom module

Now you can use the push_notifications module to send messages from your custom module. The below example will send a message to the node user when someone comments on the node.

There are many other useful functions in the push_notifications module. You can find more details about the module in our article: Drupal Push Notifications Module’s Functions List (API Manuel).