【问题标题】:Drupal Notifications module - how to obtain a subscription id (SID)?Drupal 通知模块 - 如何获取订阅 ID (SID)?
【发布时间】:2010-10-10 15:50:56
【问题描述】:

我想在论坛主题列表页面上显示订阅/取消订阅链接,以及列表中的每个主题。我在 mytheme_preprocess_forum_topic_list() 的 $topic 变量中有订阅链接的所有信息:

foreach ($variables['topics'] as $id => $topic) {

假设我想调用 notifications_get_link() 来获取取消订阅链接,我如何获取主题节点的任何现有订阅的订阅 ID (SID)?

我想我应该调用 notification_user_get_subscriptions(),但文档有点薄。举个例子就好了。

【问题讨论】:

    标签: drupal notifications subscription


    【解决方案1】:

    我的解决方案会为当前节点找到一个订阅(如果存在),并组成一个可用于模板的订阅或取消订阅链接:

    // find subscription
    $subs = notifications_user_get_subscriptions(
            $user->uid,
            'node',
            $topic->nid, 
            $topic,     
            FALSE);
    
    // compose link
    $destination = "?destination=forum/idea-exchange";
    if ($subs) {
       foreach ($subs as $key => $sub) {
          $link = notifications_get_link('unsubscribe', array(
                  'sid' => $sub->sid, 
                  'confirm' => FALSE));
          $variables['topics'][$id]->subscribe_link = 
             '<a class="unsubscribe" href="/'.$link['href'].
                   $destination.'">'.t('Stop tracking this topic').'</a>';
          break;
       }
    }
    else {
      $link = notifications_get_link(
            'subscribe', 
            array('uid' => $user->uid, 
                  'type' => 'thread', 
                  'fields' => array('nid' => $topic->nid), 
                  'confirm' => FALSE));
      $variables['topics'][$id]->subscribe_link = 
          '<a class="subscribe" href="/'.
           $link['href'].$destination.'">'.t('Track this topic').'</a>';
    }
    

    我最终为此使用了 CCK 计算字段,以便可以将其包含在视图中。有关详细信息,请参阅this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-08
      • 2023-01-25
      • 1970-01-01
      • 1970-01-01
      • 2017-08-26
      • 2017-11-22
      • 1970-01-01
      • 2019-10-20
      相关资源
      最近更新 更多