Получить следующий узел / статья текущего автора - Drupal 7 - PullRequest
0 голосов
/ 23 февраля 2012

У меня есть ссылка на узле определенного автора . Все, что мне нужно, это когда я нажимаю на ссылку, я хочу перейти на следующий узел того же автора .

1 Ответ

1 голос
/ 24 февраля 2012

Один из способов, который я могу придумать, это связать его с обратным вызовом меню (то есть с элементом меню с типом, установленным в MENU_CALLBACK), скажем, node-by-author-after/%node с методом ниже, установленным в качестве обратного вызова страницы:

  /**
   * Page callback that redirects the current user to the next node of the same
   * type by the same author
   *
   * @param $prev
   *   Node entity that was previously visited
   * 
   * @see hook_menu().
   */
  function [module]_next_node_by_author($prev) {
    // Previous node is not valid
    if (!$prev || !isset($prev->nid)) {
      drupal_not_found();
      return;
    }

    $uid = &$prev->uid;
    // User exists and is active
    if ($account = user_load($uid) && $account->status) {
      // Get next node (same type) of this user that I have access to
      $next_nid = 
        db_select('node', 'n')
          ->fields('n', array('nid'))
          ->condition('n.uid', $account->uid)
          ->condition('n.type', $prev->type)
          ->condition('n.nid', $prev->nid, '>') 
          ->addTag('node_access')
          ->orderBy('n.nid', 'ASC')
          ->range(0, 1)
          ->execute()
          ->fetchField();
      if (!empty($next_nid) && is_numeric($next_nid) && ($next = node_load($next_nid))) {
        $uri = node_uri($next);
        drupal_goto($uri['path']);
        return;
      }
      else {
        drupal_set_message(t('There are no more @types by @name', array('@type' => $prev->type, '@name' => format_username($account)));
        drupal_goto('<front>');
        return;
      }
    }
    else {
      // Go back to the previous node
      drupal_set_message(t('The author of this @type is either not on @site or has been blocked', array('@type' => $prev->type, '@site' => variable_get('site_name', 'Drupal'))));
      $uri = node_uri($prev);
      drupal_goto($uri['path']);
    }
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...