0

如何在 Drupal 7 中设置组上下文?

我在 og_context api 中找到了这个:

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

使用菜单系统获取或设置组上下文。

参数

$group_type:按组类型获取的上下文。默认为“节点”。

$group:可选;要设置为上下文的组实体。

返回值

以组类型和组 ID 为键的数组,如果未找到上下文,则为 FALSE。**

但是我还没有找到任何如何输入“组实体”的示例。我只知道我想使用的组节点 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 回答