You are here

function notifications_ui_build_links in Notifications 6.2

Same name and namespace in other branches
  1. 6 notifications_ui/notifications_ui.module \notifications_ui_build_links()
  2. 6.3 notifications_ui/notifications_ui.module \notifications_ui_build_links()

Build subscription options as an array of links

These links can be added as node link elements or rendered some other way

Parameters

$options: Array of subscription options, like the one produced by notifications_ui_subscribe_options()

$prefix: Prefix to use for the link indexes

2 calls to notifications_ui_build_links()
notifications_ui_link in notifications_ui/notifications_ui.module
Implementation of hook_link()
notifications_ui_user in notifications_ui/notifications_ui.module

File

notifications_ui/notifications_ui.module, line 367
User Interface for subscriptions modules

Code

function notifications_ui_build_links($options, $prefix = 'notifications_') {
  global $user;
  $links = array();
  foreach ($options as $index => $option) {
    if (!empty($option['subscription'])) {

      // Unsubscribe link
      $title = t('Unsubscribe from: !name', array(
        '!name' => $option['name'],
      ));
      $props = notifications_get_link('unsubscribe', array(
        'sid' => $option['subscription']->sid,
        'destination' => $_GET['q'],
      ));
    }
    else {

      // Subscribe link
      $title = t('Subscribe to: !name', array(
        '!name' => $option['name'],
      ));
      $props = notifications_get_link('subscribe', array(
        'uid' => $user->uid,
        'type' => $option['type'],
        'confirm' => TRUE,
        'fields' => $option['fields'],
        'destination' => $_GET['q'],
      ));
    }
    $links[$prefix . $index] = array(
      'title' => $title,
      'html' => TRUE,
      'href' => $props['href'],
    ) + $props['options'];
  }
  return $links;
}