0

Drupal 7 でグループ コンテキストを設定するにはどうすればよいですか?

私は og_context api でこれを見つけました:

**> 7 og_context.module og_context($group_type = 'node', $group = NULL)

メニュー システムを使用してグループ コンテキストを取得または設定します。

パラメーター

$group_type: グループ タイプ別に取得するコンテキスト。デフォルトは「ノード」です。

$group: オプション; コンテキストとして設定するグループ エンティティ。

戻り値

グループ タイプとグループ ID をキーとする配列、またはコンテキストが見つからない場合は FALSE。**

しかし、「The group entity」の入力方法の例は見つかりませんでした。使用したいグループ ノード ID (たとえば、「40」) を知っているだけです。

誰でもこれで私を助けることができますか?ありがとう!

4

2 に答える 2

0

ここで解決策を見つけました: https://drupal.org/comment/8179187#comment-8179187

arg(1) がグループ ノード ID であると仮定します。

$node = node_load(arg(1));
og_context('node', $node); // Set og context
于 2014-02-13T22:44:37.713 に答える
0

これは私にとってはうまくいきましたhttp://cgit.drupalcode.org/og_extras/tree/og_extras.module?h=7.x-1.x#n147

function mymodulename_og_context_negotiation_info() {
  $providers = array();
  $providers['mymodulename'] = array(
    'name' => t('mymodulename url'),
    'description' => t("Select group context for any url that starts with 'group/%'. Make sure that all views and custom pages use paths that start with this value in order for the context to be recognized when viewing those pages, and that nothing that is not a group uses that path."),
    'callback' => 'mymodulename_context_handler_url',
  );
  return $providers;
}

/**
 * Context handler; Get groups from URL.
 */
function mymodulename_context_handler_url() {
  $context = array();
  if (arg(0) == 'group' && is_numeric(arg(1))) {
    $context = array('node' => array(arg(1)));
  }
  return $context;
}
于 2016-05-04T19:20:51.157 に答える