You are here

function notifications_ui_link in Notifications 5

Same name and namespace in other branches
  1. 6.4 notifications_ui/notifications_ui.module \notifications_ui_link()
  2. 6 notifications_ui/notifications_ui.module \notifications_ui_link()
  3. 6.2 notifications_ui/notifications_ui.module \notifications_ui_link()
  4. 6.3 notifications_ui/notifications_ui.module \notifications_ui_link()
  5. 7 notifications_ui/notifications_ui.module \notifications_ui_link()

Implementation of hook_link()

Add subscriptions links to nodes

File

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

Code

function notifications_ui_link($type, $node = NULL, $teaser = FALSE) {
  global $user;
  $links = array();
  if ($type == 'node' && $user->uid && (variable_get('notifications_link_teaser', 1) || !$teaser) && notifications_ui_type_options($node->type, 'links')) {

    // Now we have the array of allowed options ready, build links
    foreach (notifications_ui_user_node($user, $node) 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,
        ));
      }
      else {

        // Subscribe link
        $title = t('Subscribe to: !name', array(
          '!name' => $option['name'],
        ));
        $props = notifications_get_link('subscribe', array(
          'type' => $option['type'],
          'confirm' => TRUE,
          'fields' => $option['fields'],
        ));
      }
      $links['notifications_' . $index] = array(
        'title' => $title,
        'html' => TRUE,
      ) + $props;
    }
  }
  return $links;
}