The following Pathauto tokens no longer exist.

[ogname] - Title of top group
[ogname-raw] - Unfiltered title of top group. WARNING - raw user input.
[og-id] - ID of top group
[og-type] - Type of top group
[ogalias] - URL alias for the top group.


What can I use to substitute for these missing tokens?


Project:Organic groups» Token
Component:og.module» Code
Status:Active» Closed (duplicate)

Title:OG Aliases missing from D7 branch?OG (Organic Groups) token's missing.
Status:Closed (duplicate)» Active

I think I preemptively closed this.

I'm following this issue que, but it doesn't look to have resolved this.

#691078: Field tokens


Project:Token» Organic groups
Component:Code» og.module

Organic groups historically has provided organic group's tokens.

Status:Active» Fixed

Check out the -dev, I've just added yesterday tokens support.

This one?

7.x-1.x-dev tar.gz (141.74 KB) | zip (176.75 KB) 2011-Mar-08 Notes

Thanks for your work Amitaibu. I just installed the dev and I got a few new options to show up :) I'm still looking for "group_audience" or a facsimile of it. I'll keep tabs on this issue que, I really appreciate your hard work.

I'm using -dev from March 14th, and I'm afraid I don't see organic group tokens even after applying the tokens module patch from

Now I see other field api tokens, but nothing from organic groups.

Status:Fixed» Active

@ jastraat,
DO you have Rules installed? You can see the og tokens being used with the default Rules that come with og -dev.

I do not have rules installed. I'm trying to use og tokens with pathauto.

> I'm trying to use og tokens with pathauto.

You will not see the og tokens, as they don't have a group context.

This confuses me I'm afraid; if I add a group audience field to a content type, the value I store in a node won't be available for pathauto to use..?

new3.71 KB


The following patch tries to enhance OG tokens a bit, introducing the following changes:

  • Remove global "group-manager" tokens (they were declared with no data requisistes, yet needed a user object to work)
  • Added a "node" subtoken to the "group" type, so all node tokens can be used (e.g: [group:node:summary]).
    • D7 Organic groups are not node-based but entity-based.. i asked Amitaibu about this for guidance to find the right solution, so stay tuned because this means this patch (and the tokens generated) are very likely to change, if ever included in og
    • Most important fields on group:node tokens are actually in the group token itself: title (as label), url, etc.
  • Added a "manager" subtoken to the "group" type, so all user tokens can be used (e.g: [group:manager:mail]).
    This would have to be renamed to "admin", i suppose, since it fetched the user object via it's entity (node) author
  • Added a global "current-group" token, which is enabled when the submodule "og_context" is enabled.

I use this patch mainly together with menu_tokens module to provide some wierd menus (if you happen to do the same thing, make sure to use the -dev version, due to #1092820: Current page tokens cannot be verified when savin menu item).

Also, the problem exposed by #7 and #11 is related to accessing arrays of data using tokens, and it's being discussed on this token module issue: #1047740: Add an [array:*] token type and a [user:roles] token.
I think the most reasonable approach by now would be to wait for them to define a nice scheme to access fully typed arrays with tokens, and stick to it. Myself, I created a custom token that just returns the first group listed in the audience, but it's useless if you happen to use multiplicity on audiences.

new1.15 KB

This patch has the simple node audience token i was using for pathauto, ported to be applied over the last one in #14.

Just thought I would share this as an example for #7 and #11. My advise would be to create a custom module and register those tokens there using custom names (e.g: my node subtokens are called "qr-ognode", and directly return the group node instead).

I am also looking for passing gid to pathauto, is there a way to do so?

Status:Active» Needs work

Thanks for working on this.

+++ b/
@@ -15,11 +15,13 @@ function og_token_info() {
+  if(module_exists('og_context')) {
+    $types['current-group'] = array(
+      'name' => t('Current group'),
+      'description' => t('Tokens related to the current group as found via OG\'s context module settings.'),
+      'type' => 'group',
+    );
+  }

This should be in og-context module.

+++ b/
@@ -42,9 +44,23 @@ function og_token_info() {
+    'description' => t('The main node that identifies this group'),

Missing dot in end of line.

+++ b/
@@ -66,7 +82,14 @@ function og_tokens($type, $tokens, array $data = array(), array $options = array
+      // Get first subtoken only
+      $piece = $name;
+      if(($pos = strpos($name,":")) !== FALSE) {
+        $piece = substr($name,0,$pos);
+      }

Please add in the documentation why this is needed.

+++ b/
@@ -85,6 +108,32 @@ function og_tokens($type, $tokens, array $data = array(), array $options = array
+              && ($user = user_load($entity->uid))

use a variable called $account instead of $user (as objects are passed by reference, and we don't want to have a security risk that the $user object will change).

+++ b/
@@ -94,8 +143,10 @@ function og_tokens($type, $tokens, array $data = array(), array $options = array
+  if ($type == 'current-group' && module_exists('og_context')) {
+    if ($group = og_context()) {
+      $replacements += token_generate('group', $tokens, array('group' => $group), $options);
+    }

Move this to og-context.

Powered by Dreditor.

+1 for everyone working on this.

Is patch #14 rolled into the token branch?

new4.24 KB
new3.24 KB

I've just reviewed the patch i submitted to take into account amitaibu's suggestions:

  • Moved og_context related tokens to it's own og_context/ file
  • Moved all sub-token parsing out of the foreach bucle, which was really stupid.
  • Now "node" and "manager" tokens return group url and manager user name when you're not using any subtokens on them (e.g: use [group:node] directly)

Also, the second patch i submit (noerrors) makes any undefined tokens not generate any replacement pairs at all.

Rationale: Invalid tokens usually generate no replacements (e.g: unexistant fields, chained access on undefined elements, etc.), and this case is treated nicely by pathauto, which simply deletes any unreplaced tokens. I couldn't find if this behaviour is defined or not by D7 specification, but allows some nice things, like setting "[node:simple-audience:url:alias]/issues/[node:title]" as url for some group content types, which would result on /pathto/mygroup/issues/node-title, yet allowing fallback to /issues/node-title when no group audience was selected.

Btw, the audience token patch was not merged in, yet.

#16 -> Using latest git/dev release of og, and applying the horrible patch on #15 you should be able to use [node:simple-audience:gid] on pathauto. You'll have to apply the patch by hand, and expect inconsistencies and token name changes whenever (if ever) it gets into mainstream og.

I'm going to push my luck here -- quimrovira, any chance for some tests with this patch ? :)

I'll be happy to provide some tests as as soon as i have some spare time to write them down :)

new10.1 KB

New version of the noerrors patch, that includes mostly everything above except the [node:audience:*] tokens, and also a new set of tests for OG tokens. Also, [group:manager:*] tokens are no longer node-only, since they should work with any entity (i think).

I've placed the token tests on the main og.test file. They all pass on a clean d7 installation with the git 7.x-1.x version, so far.. post any fails here and I'll try to fix them asap!

Status:Needs work» Needs review

fix status to trigger testing!

Thank you to everyone working on this...I was using the 7.x-1.0 Jan 5 release and as a non-programmer was finding it challenging to keep up with the patches and discussions and decided to wait for a more stable version. I then uninstalled OG and went about developing other parts of the site. I upgraded to the Mar. 23 dev release this morning and could not get the approve member function to work. The person asking for permission would appear on the group manager's group tab and when clicking update the green message bar would still say it was updated but the status would remain pending. At first I thought it was a conflict with Content Access which I'd installed in the interim so I uninstalled that and still had the problem. After trying every config of permissions and fields I could think and uninstalling and re-installing several times I finally uninstalled it and went back to the Jan 5 release and that works OK.

On one of my installs this is the message I received on the white screen of death when I tried to update a member status: Fatal error: Unsupported operand types in /Users/xxxxxx/xxxxxx/version2/sites/all/modules/og/og.module on line 1468

Again, thanks to all, I am very, very grateful for all your work.

For what it's worth, there is a conflict with Control Access...any content I had limited access on, all the fields disappeared when I enabled OG. After several attempts I tried it iwthout enabling the OG field access and I controlled field access with Control Access and got it all back...I'd be grateful for any suggestion about how I should go about this. My site goes live in just over a couple weeks with the launch of a book in Washington and NY that will bring many folks to it wanting to sign up.
Thank you again.

No offense, cartagena, but you should try to post such information on it's own issue. Take into account that posting on any unrelated issue causes confusion and makes managing the open issues for mantainers more difficult ;)

If you look at the original issue in this page, you'll see that we're all discussing about a very specific organic groups feature: token support.

Reading your two comments, I guess your membership approval problems are related to these issues: #911256: Adding user to a group fails and/or #1103002: group/%/%/admin/people membership 'state' is not set correctly

Thank you, quimrovira. I did find the other issue page. I'm new to this and I'm not always sure what to search for or what the correct terminology is for the problem I'm having. Guidance is welcome. I'll be more careful.


Great I'll go over it.

Other people, instead of "subscribe" you should test the patch...

I want to test. How does one apply these patches? I have recently pulled the latest code from the git repo. I downloaded the patches to my og working directory and tried to apply the patches, but:
~/Sites/field/drupal/sites/all/modules/og$ git pull
Already up-to-date.
~/Sites/field/drupal/sites/all/modules/og$ ls -l *.patch
-rw-r--r--@ 1 rkoberg staff 1174 Mar 27 09:00 og-horrible-first-audience-met.patch
-rw-r--r--@ 1 rkoberg staff 3316 Mar 27 09:01 og-tokens-met-2-no-errors.patch
-rw-r--r--@ 1 rkoberg staff 4343 Mar 27 09:01 og-tokens-met-2_0.patch
~/Sites/field/drupal/sites/all/modules/og$ git apply og-horrible-first-audience-met.patch
error: patch failed:
error: patch does not apply

Is there someplace I can just grab the already modified files?

You need to use only a single patch -- the latest one posted, not all posted patches. Thanks for testing it out.

This seems to work fine as is. Hoping for more :)

In my case, I have created group hierarchies and want to have the URL alias built up from the parent group's URL (the group audience URL). What is the most efficient way to get a $group->group_audience path? My try below works, but could use help and any advice would be appreciated. It allows me to create a URL Alias for the group hierarchy like so:


What I have done so far is add to (at line 18):

  $types['group-audience'] = array(
    'name' => t('Group Audience'),
    'description' => t('Tokens related to the current node\'s group audience or parent as found via OG\'s context module settings.'),
    'type' => 'group',

and in at line 72:
  if ($type == 'group-audience' && $group_audience = $data['node']->group_audience) {
    $parent = og_get_group('group', $group_audience['und'][0]['gid']);
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'url':
          $replacements[$original] = drupal_get_path_alias('node/' . $parent->getEntity()->nid);
  } else if ($type == 'group' && !empty($data['group'])) {

@RobKoberg: This is essentially what the horrible patch in #15 does. The reason why it has not been considered yet is because it looks like there's no consistent way to treat arrays using tokens, and I'm currently waiting for feedback on a similar issue on the token module: #1047740: Add an [array:*] token type and a [user:roles] token, where they provide a few useful tokens, but only for scalar/string types, and we've got an array of groups here.

Anyway, as I said, I'm currently using the same approach as you, while we wait for that. ;)

There are in the dev some Rules configuration that are using tokens. I think this patch will break, since the tokens are renamed, no?

Ok, I'll try to check that ;)

Status:Needs review» Needs work

Can you re roll patch using --no-prefix, so I can apply the patch and test it?

+++ b/og.test
@@ -1209,4 +1209,120 @@ class OgUpgradePath7001TestCase extends OgUpgradePathTestCase {
+    $this->group_node_type = $this->drupalCreateContentType( array( 'name' => 'group' ) );

Too many spaces, shoudl be (array('name' => 'group'));

+++ b/og.test
@@ -1209,4 +1209,120 @@ class OgUpgradePath7001TestCase extends OgUpgradePathTestCase {
+    $this->assertEqual(token_replace("[group:gid]", array("group" => $group) ), $group->gid, t('Generation of "[group:gid]" token for entity groups'));

Assert message should end with a dot (.)

+++ b/og.test
@@ -1209,4 +1209,120 @@ class OgUpgradePath7001TestCase extends OgUpgradePathTestCase {
+    $this->assertEqual(

Lets have the assertion in one line. You can have $value1, $value2 as variables to do the assertion, so the line won't be too long.

+++ b/og.test
@@ -1209,4 +1209,120 @@ class OgUpgradePath7001TestCase extends OgUpgradePathTestCase {
+    // Test token chaining on node subtoken (node)
+  function testOgNodeGroupTokens() {

We are testing also the users here, so the name isn't so good. Maybe testOgEntityTokens?

+++ b/og.test
@@ -1209,4 +1209,120 @@ class OgUpgradePath7001TestCase extends OgUpgradePathTestCase {
+    // Test token chaining on created subtoken (date)

This test seems to be in previous test already. Aslo we should test for a token of a group:node:title , that is not a node.

+++ b/
@@ -42,6 +36,18 @@ function og_token_info() {
+    'name' => t('Manager user'),

Maybe better "Group manager user".

+++ b/
@@ -69,33 +75,56 @@ function og_tokens($type, $tokens, array $data = array(), array $options = array
-          $replacements[$original] = !empty($group->gid) ? $group->gid : t('not yet assigned');
+          if(!empty($group->gid)) {
+            $replacements[$original] = $group->gid;
+          }

Why do you change this -- we might pass a group that still wasn't save.

+++ b/
@@ -69,33 +75,56 @@ function og_tokens($type, $tokens, array $data = array(), array $options = array
+      if (($entity = $group->getEntity()) && ($account = user_load($entity->uid))) {
+        if ($entity = $group->getEntity()) {

No need to if the $group->getEntity(), there is no reason to not get it. Removing it will make it a little more readable.

Powered by Dreditor.

@Amitaibu: --no-prefix is on its way out. You can read about how to apply patches created without that at

I have created a tokens branch --

This is the last task on my todo before a release.

Ok, I'll review this today to avoid keeping back the next release.

About your comments on the above snippets:

  1. ok
  2. ok
  3. ok
  4. hmm i'll review that, although the difference between the two test classes is the type of entity that defines the group (node-based groups being ust one case, were the :node token would not apply)
  5. right!
  6. ok
  7. Well, I removed this along with two or three other defaults to cover the case where missing or unreplaced tokens is nicely handledd by the calling module (e.g: pathauto strips away any of them, while returning "not assigned yet" would render a /.../not-assigned-yet/... alias). What do you think would be better here?
  8. You're right again, I'll remove the extra checking

You can pull from the tokens branch, and create your own branch in the sandbox, like this we can pull from each other.

When trying to update the member status in a group I receive the same error message as #25. Is this an issue that has something to do with tokens? If not should I open up another issue for this? Here is the call stack:

# Time Memory Function Location
1 0.0016 331488 {main}( ) ../index.php:0
2 1.0813 31917652 menu_execute_active_handler( ) ../index.php:22
3 1.0847 32143356 call_user_func_array ( ) ../
4 1.0847 32143624 drupal_get_form( ) ../
5 1.0847 32144264 drupal_build_form( ) ../
6 2.5957 45684504 drupal_process_form( ) ../
7 2.6000 45724740 form_execute_handlers( ) ../
8 2.6000 45726720 og_ui_user_admin_account_submit( ) ../
9 2.6009 45730328 call_user_func_array ( ) ../
10 2.6009 45730344 og_ui_user_operations_block( ) ../
11 2.6009 45730372 _group_ui_user_operations_set_state( ) ../og_ui.module:555
12 2.6010 45730796 og_group( ) ../og_ui.module:573

new7.76 KB

Applied the suggested changes on a sandbox at (I've given amitai full access just in case)

Patch also attached, but it was generated against the token branch, not 7..x-1.x!

I have pushed some code cleanup in my branch. I have noticed you have

    // Create a group content node
    $cnode = $this->drupalCreateNode(array(
      'title' => $this->randomName(),
      'type'  => 'article',
      'uid' => $admin_user->uid,
      OG_AUDIENCE_FIELD => array( LANGUAGE_NONE => array( array('gid' => $group->gid))),

which is never used.

Yes, it was left behind because of the node:audience tokens which are not yet on the git repo..

if you think a token for the first audience field value should get into the release, i can commit my node:simple-audience token too (could take a while to get the base typed array support into token module, and i haven't had much time to look into that)

> if you think a token for the first audience field value should get into the release

Better than nothing I guess ;)

+1 for "token for the first audience field value"

> where missing or unreplaced tokens is nicely handledd by the calling module
> What do you think would be better here?

I'd like to imitate user.module -- which returns "not yet assigned" (as currently the code in tokens branch does).

We also need to add token for og-membership entity (and move [created] from group to og-memnbership). After that we can fix the Rules integration.

Oh MY! I have completely missed the fact that entity API already provides token integration :/ So most of the work was already by implementing the metadata class...


I've been trying my hardest to apply these series of patches and custom dev work-arounds to support og assignments on nodes to display in pathauto's URL aliases.

I can't seem to get the first audience value to populate using steps listed in this issue. Mainly quimrovira's #20 post regarding #16. [node:simple-audience:gid] returns a generic invalid token error.

If you have another option as a work-around, please let us know; if one of the suggestions above is the best option, I'll get back to the drawing board. :)
Thanks for all your work.

The token is now implemented in the -dev version -- you need to enable entity-token module.

Note that indeed until #1047740: Add an [array:*] token type and a [user:roles] token there is no support for tokens that are a list (so you can't do for example [node:og_membership(1):group:label]; however on a group node you can [node:group:label].

I'll keep on needs work until I update docs.

One big sorry for letting you do the hard work and in the end taking another approach, but I think it's for the best. Do stay in OG's issue queue ;)

Amitaibu I just tried the most recent dev build, but I'm not seeing any additional tokens. I ran update.php, but it said nothing needed to be updated. I'm using Entity API and Entity tokens 7.x-1.0-beta8

Am I missing something?

> Am I missing something?

You missed my comment:
> Note that indeed until #1047740: Add an [array:*] token type and a [user:roles] token there is no support for tokens that are a list (so you can't do for example [node:og_membership(1):group:label]; however on a group node you can [node:group:label].

Thanks Amitaibu

I'm still here, but i was away mostly due to easters.. I'll try to get back to this issue the next few days and sort it out!

Issue tags:+token

Tracking as token maintainer.


Amitaibu, I just upgraded to the new Beta 2 Token release and I noticed some possibly new options.

Does this resolve the current hurdle of #1047740: Add an [array:*] token type and a [user:roles] token?

EDIT: I just remembered I am using this token patch from #143 as suggested by #262. #691078: Field tokens

I'm using the latest dev of og and can't use [node:group:label] in my url patterns. I have entity token beta8 in use. I'm probably missing something but just can't see what that is.

allthough i just found this [site:current-group:label] which seems to be giving current groups name...

Status:Needs work» Fixed

I've Added docs about views/ rules/ tokens integration and FAQ section, so marking fixed.

Status:Fixed» Active

I'm afraid I'm still having difficulty with organic groups + pathauto. I am using the following modules:
Entity API (with Entity tokens enabled) 7.x-1.0-beta8
Token 7.x-1.0-beta2 + the field tokens patch:
OG 7.x-1.1-rc3

I'm not seeing any tokens related to organic groups except:
[node:group-group] and [node:group-theme]

None of the following work:

Please - what am I missing? Thank you in advance!

I have same problem as jastraat have (with same modules versions).

I seeing [node:group-group] and [node:group-theme], but none others.

I'm trying with og-7.x-1.1-rc3 too, but without luck ...

Any ideas?

> None of the following work:

You mean you don't see them on the list, or when you add them it doesn't get the token?

I'm using the following without any patches applied
Drupal 7.x-2.0
OG 7.x-1.1-rc3
Entity API 7.x-1.0-beta8
Token 7.x-1.0-beta2

When looking at pathauto I only see "[node:group-group]", I do not see [node:group-theme]

If I try to use "[node:group-audience]" or "[node:group:label]" with pathauto, I am unable to and I get the following warning.

The Pattern for all Page paths is using the following invalid tokens: [node:group-audience].

SOLUTION: To get the current group the node is posted to, you can use [site:current-group:label]

@Amitaibu Both - the tokens do not appear in the list and they do not work when entered.

@animelion - [site:current-group:label] did not work when I tried it. Pathauto accepted it as a token, but it did not generate anything for the path when creating a new group content node (which is what I applied the token to.)

Based on the screenshot above, I tried [site:current-group:url]. This did work but it takes the FULL url path - including the site base url. It seems like the token should only include the 'path' portion of the group's url -

It's worth mentioning that unless using a query string appended to the node add url, pathauto won't have a 'current-group'.

Interestingly, [site:current-group:label] does display as a possible token when configuring file paths for image fields. It works for the most part, with one strange problem.

If you create a multi-value image field, the first image uploaded goes to the correctly named directory. The SECOND file (and all subsequent ones) go into a directory called '[site:current-group:label]'; the token is apparently not parsed. If the user uploads one file, then saves, then uploads another, the token works as expected. To try to establish if this was a core problem with tokens, I tried using the [current-user:name] token. That token worked as expected with multiple files all going into the correct directory, so I believe this is a problem specifically with OG's tokens or possibly with the Entity API.

new794 bytes

For my need's, i've created new module for OG tokens (see attachment).

After install we have new token: [group:uri] (work for new and exists nodes).

@jupeter -
This is a cool idea. However - it looks like you're using $gid for $nid when those aren't the same thing.
gid is the Group ID, not the Node ID. You'd need to do something like:
$node = og_load_entity_from_group($gid);
to get $node->nid

Just tried this module out with the following changes:

case 'uri':
$node->group_audience['und'][0])) {
$gid = $node->group_audience['und'][0]['gid'];
$groupnode = og_load_entity_from_group($gid);
$replacements[$original] = url('node/' . $groupnode->nid);

And it appears to work like a charm with pathauto. And it doesn't require the query string for the group to be passed through the URL for creating new content which is really nice.

Any chance of this getting into the OG module?

Thanks for the module and the fix...but I must be doing something wrong. I am using latest dev version of og, views, modules, token etc. I now get the new og tokens when I go to set url patterns. But the only one that works is group:uri. I've attached screen shots of what I'm looking at. Any suggestions would be most appreciated. I've cleared cache numerous times. And still can't get any other patterns. Thanks!

I have added a fix to get [node:group:label] working again.

Thank you! I've got my groups set up on my test server, hope to make them live very soon. I am simply AMAZED at what I can do with OG, panels, views and rules as far as having private and public groups and content. Add a little css and some theming and it's great! Still trying to understand contexts and relationships for some additional things I want to do, but even so, what all you developers have done is incredible. Thanks again, it's incredible!

Thank you! I've got my groups set up on my test server, hope to make them live very soon. I am simply AMAZED at what I can do with OG, panels, views and rules as far as having private and public groups and content. Add a little css and some theming and it's great! Still trying to understand contexts and relationships for some additional things I want to do, but even so, what all you developers have done is incredible. Thanks again, it's just awesome!

#71 worked for me!
Thank you

Hi there,

I'm running the dev version from today, and the new tokens appear in the list, but they don't actually work (that is, they come out blank).

Any suggestions?

From my comment in #73 -
Unless you are using a query string appended to the node add url, pathauto won't have a group context to populate the tokens.

I'm using the latest dev versions of everything, OG, Entity, Entity Tokens, Pathauto, and I see all of the group tokens as options but none of them work. I have tried both the node:group and the site:current-group tokens (and numerous variations of them, like site:current-group:labels) and absolutely none of them do anything in pathauto patterns. When I delete and recreate my aliases, all of them end up empty.

I'll have to recheck.

Another option you guys and gals should check is using Rules to set the path. I think Rules can better manipulate the tokens than pathauto.

I'm using the latest non dev releases on a D7 proof of concept: Organic groups 7.x-1.1, Pathauto 7.x-1.0-rc2, Entity API 7.x-1.0-beta10, Token 7.x-1.0-beta5, etc...

I have been able to use [node:group_audience] in my Group Content's URL Patterns but I must not hide the Group Audience field for my content type. I don't typically want to see the Group Audience field in the content area so I'm using CSS to hide it but it does work as a replacement pattern. I haven't been able to get any of the others to work though ([node:group-group], [node:group], etc...).

My goal is to include the taxonomy term of the Group ([node:group_audience]) that this content falls under but I haven't had any success yet. The replacement will hopefully then be something similar to:


If the tokens are appearing blank then it would mean that the data is not provided properly in token replacement. Not sure how Rules would fix that.

@Dave Reid: That's the conclusion that I came to in my tinkering with Token/Entity Tokens while trying to create some patterns in Pathauto. I think everything that has data is actually showing up.

On a sideline and this being the case, if I need to extend my tokens so that I can grab a reference to the Taxonomy term of an OG Audience or the Taxonomy term of the Organic Group a piece of content belongs to, what's the direction I should be looking in? I am truly baffled.


Currently the only way I can get this working is to set BOTH Pathauto and Rules to [site:current-group:label]/[node:title]. Strangely either of them alone doesn't work.

I needed a token today that outputs the labels of the groups a node belongs to. I could not get it to work using [node:group_audience].

I really needed this functionality so I created a small module that provides a new token [node:og-group-audience]. This outputs group labels as a comma separated list, or allows to retrieve a single group label by using the array functions of the Token module.

My use case was to generate custom URL aliases that contain the group name using Pathauto. I needed a filename pattern like 'group/[node:og-group-audience:first]/event/[node:nid]'.

@Dave Reid

If the tokens are appearing blank then it would mean that the data is not provided properly in token replacement. Not sure how Rules would fix that.

All the tokens in OG are actually defined via entity-metadata and "exposed" via entity-tokens module. Some properties can't be used as token -- #1058856: Entity tokens not created for multi-value fields. However Rules itself, can you those metadata properties (even lists), so one doesn't actually use tokens but the metadata system itself.


Most of the og tokens aren't available to rules. You can access them in the data selection of rules but they don't have values (check gid). Really ugly workaround: create an extra field and save the data on hook_form_alter until this is fixed!

> You can access them in the data selection of rules but they don't have values (check gid)

You are right, I though the data selectors are available also on "direct input" mode.

@Amitaibu: I think you got me wrong it doesn't matter if you use 'data selector' or 'direct input' mode. The value of e.g. 'gid' is always empty.


The thing is that OG doesn't have even a single line of code that deals with tokens. Entity-tokens module just takes the metadata info from OG, so I suspect it should be handled upstream -- as Entity API's issue.

Do you have a clue what it could be? I could open an issue in the entity api issue queue or do you want to do it? Rules integration is kind of crucial for me... As far as i get it: if you implement hook_entity_property_info() properly rules and all the stuff is for free :) You did that so i have no idea what could be wrong... I will have a better look at hook_entity_property_info() later!

@Amitaibu: Sorry for spamming, but couldn't it be related to the bugs related to arguments and relationships in views? I found this issue: #1041066: Passing OG arguments in Views

if (is_numeric($arg)) {
$group = og_get_group('node', $arg);
$arg = $group->gid;

Please correct me: Arguments in views only work when overwritting the nid (argument) with the group id? Since the tokens are exposed to UI but there are empty couldn't be the same think happening here?

I don't think that's it's related to #98 but it could be related to: #1058856: Entity tokens not created for multi-value fields

I opened a new issue in the entity api queue:

#1320916: token support for organic groups

I just ran into that issue too. Well, the problem is that the og relations are so generic, e.g. this gets me the group node of a content node:

-> [node:og-membership:0:group:entity]

Of course, there are no generic-entity tokens though... Also, this results in bad SBX (site builder exp :D) in Rules. Although it's rather complicated in Views too :(

I'd prefer being able to just use it that way:

E.g. by using separate membership properties by membership type? Then we can associate group-fields with membership types + restrict the group-entity type by membership type. That should be fine as usually I don't want to have different entities for the same kind of group.

-> That would already easy the case for getting from group content to the group entity. E.g. it could be
[node:group-membership:0:entity] which is declared to be a node - that way tokens like [node:group-membership:0:group:entity:title] would work out-of the box.

Then, I wonder whether there is still a use-case for having the group-entity as we have group memberships now? Removing that would also make it much simpler, including Views. But that's probably out-of-scope to change it now :(

Additionally, we could restrict possible group membership types in the group-audience field settings. That way, we could generate *useful* membership properties per-field.

> I'd prefer being able to just use it that way:

The problem is that og_membership points to the group ID, and changing it to point to the entity_type and entity_id can make stuff more complicated (things like entityFieldquery).

> Then, I wonder whether there is still a use-case for having the group-entity as we have group memberships now?

Funny, just yesterday I was thinking if we really need the group entity. I think we still do as we need a group ID, and we need to be able to get the group's label for autocomplete widgets.
Anyway I don't think the group membership can replace the group, as it defines the connection between a group content to a group.

> Additionally, we could restrict possible group membership types in the group-audience field settings

It's actually happening in #1263588: Allow having multiple group-audience type fields (you should check that branch out :D), where you define a membership type per group audience field (this allows having a subscribe link per membership type). How would that help with the token, though?

Funny, just yesterday I was thinking if we really need the group entity. I think we still do as we need a group ID, and we need to be able to get the group's label for autocomplete widgets.

Oh, I think entity_reference does that already directly. I guess it only works if there is *no* label callback but a label key given.

Anyway I don't think the group membership can replace the group, as it defines the connection between a group content to a group.

Yes, I agree. Still, there is nothing stored in the group entity that isn't in the real group entity, not?

I'd imagine having relations like
node(group content) -> og membership -> node(group)

Whereas group metadata like "is the group enabled?" could be stored directly in group entity (node), as it is already the case for the active/pending state. Well, I'm just elaborating on the design, I know it's probably too late for such a drastic change.. :/

ad #1263588: Allow having multiple group-audience type fields
oh thanks for the pointer, very nice! :) Well, for tokens that could help making relations more predictable. If we could restrict the group entity type for a given membership type, we could do tokens like [node:membership:0:node:title] as we'd know the membership's group's entity is a node.

> Oh, I think entity_reference does that already directly. I guess it only works if there is *no* label callback but a label key given.

I'll need to check -- does it query the key directly.

Anyway, I'm not opposed of deprecating the OG group entity. It think it was a nice idea at the time, but I see over time it just holds the group Id and label. Need to think on how to implement it, though ;)

Opened issue about deprecating og group -- #1342632: Deprecate OG group entity

Can someone clarify what, if anything, currently works to get OG tokens? I've read through the issue twice and I still can't find a working solution. Fago says

this gets me the group node of a content node:
-> [node:og-membership:0:group:entity]

but I was not successful using that token in Rules or Pathauto. I'm looking for a URL that includes the gid of the group content's group, and a rule that sends an e-mail when new group content is created saying "New content posted in ." But so far no token I have tried works. Is anyone doing this successfully?

Given that pathauto requires the token module, the only token support available in og comes from entity tokens, and the two modules are incompatible when a site has a large number of fields ( - I just wrote my own module to create the tokens. The following only includes title and group path, but it could easily contain gid or whatever other token you'd like to use.

* Implements hook_token_info().
function og_token_token_info() {
$info['types']['current-group'] = array(
'name' => t('Current group'),
'description' => t('Tokens related to the current group context.'),
$info['tokens']['current-group']['title'] = array(
'name' => t('Title'),
'description' => t('The title of the current group.'),
$info['tokens']['current-group']['url'] = array(
'name' => t('URL'),
'description' => t('The URL of the current group.'),
'type' => 'url',
* Implements hook_tokens().
function og_token_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
$url_options = array('absolute' => TRUE);
  if (
$type == 'current-group') {
$current_group = og_context();
    if (isset(
$current_group->etid)) {
$groupnode = $current_group->getEntity();
      foreach (
$tokens as $name => $original) {
        switch (
$name) {
$replacements[$original] = $groupnode->title;
$replacements[$original] = url('node/' . $groupnode->nid, $url_options);
// Chained token relationships.
if ($url_tokens = token_find_with_prefix($tokens, 'url')) {
$replacements += token_generate('url', $url_tokens, array('path' => 'node/' . $groupnode->nid), $options);

Title:OG (Organic Groups) token's missing.OG (Organic Groups) tokens missing.

Thanks jastraat. I tried your module but couldn't figure out what token names to use to make it work. However, pfrenssen's OG Token sandbox module (from #91) worked perfectly and totally meets my needs. (Although neither contains a gid token, that one seems to work fine with the default entity tokens (in Pathauto, I'm using [site:current-group:gid] for group content and [node:group:gid] for groups.))

Thanks for your prompt response!

Has the [site:current-group:*] tokens been removed from the latest OG dev? This was working for me in 18bbcb389ea264fa6d703630d1e799b042cd2c3c not in the latest OG. I was previously using this in Rules to redirect to the group URL after deleting group content (by default when you delete content you end up on the site homepage, which is confusing for group managers as they then have to go and find their group again to continue what they were doing.

In Rules, I can also get a token which is node:og-membership:0:group:url which would usually work, but since this Rule is being fired after deleting content, node:og-membership:0:group:url doesn't seem to exist at that point (despite Rules presenting it as an option).

Can we get the [site:current-group:*] tokens back? They were very useful!

#91 rocks! Thanks BrightBold for the heads up.

subscribing to this issue. I use og:alias as a pathauto pattern for group content in D6 successfully, but can't find an equivalent (or really get any group tokens to work) in D7 pathauto 1.0 with OG 1.3

Looks like the og_context module has some of these missing tokens now.

Would someone in the know be able to provide a little update as to what the status is here. After upgrading to the laste 2.x release, it seems like there is no way to get to a group from a group content node in rules. Where previously we could do stuff with node:og_membership, doesn't seem like there is any kind of equivalent any more.

I also tried adding a 'Entity has field' condition and adding the og_group_ref field, but even using that with node:og-group-ref:... doesn't allow me to get to an actual group.

What am I missing?

So it seems that an equivalent of og:alias is still missing, is that correct?

I was able to utilize the module in comment #107 to provide the same functionality and it worked wonderfully, thanks!

Not quite sure where a good entry point in the code would be to get this token into the module, but it's very useful for building out group content that fits into a nice URL pattern.

I want this for a new feature in Crumbs:
I would like to allow settings like:

Parent path for nodes of type "group":

Parent path for nodes of type "group_event":

Unfortunately, the [node:group_nid] (or sth equivalent) does not exist.

Wow, entity_token seems to be a great help.
It provides e.g. node/[node:group-audience:0:etid].

So the breadcrumb settings could be:

Parent path for nodes of type "group":

Parent path for nodes of type "group_event":

Parent path for nodes of type "group_discussion":

Probably the same works for pathauto?


It should be mentioned that entity_token says group-audience (hyphen), while og says group_audience (underscore).
This looks awkward, if both show up in the token help.

It should also be noted that token help only shows
but not
Even though the :0: is the only one that works (for me).

This is great to know, thanks donquixote!

Yeah, that is good info, thanks. It did work in Pathauto, but it is the group id. If someone discovers how to get the group name in there, please post it.

Has a token for the group path been added to organic groups? I apologize if this seems like a silly and obvious question but in reading through this long discussion I didn't get a strong feeling either way. For me I have two group content types:

Facility - pathauto: facilities/[node:title]
Classroom - pathauto: classrooms/[node:title]

I also have a news content type that could be assigned to either a facility or a classroom. As a result I would like news items posted in a facility group to show up at "facilities/computer_lab/news/test_news_item" while a news item posted in a classroom might show up at "classrooms/mr_darnells_class/news/test_news_item". In order to do this I would need to capture the url for the group and append "/news/[node:title]" to it as the pathauto value for the news content type.

I found an example of this here: but it seems really dated and I'm not sure the patch would work with 7.x-2.0-alpha3...

I also noted comment #107 above from jastraat but given the age of that comment and the fact that organic groups is currently in a state of flux I thought I should ask the group directly before I implement that custom module.

Thanks @donquixote ! Based on #116, I knew that I should use 0 instead of 1 ;) (The notes on the deltas do mention that the index starts at 0... not sure why 0 items weren't included... bug?)

I created a pathauto pattern like:


In order to have the group's title in the path.

Thank you, thank you, thank you @Kristen Pol. I was tearing my hair out trying to get the GID of a referenced group to appear using pathauto and OG 7.x-2.0-beta1. Your comment was the prompt I needed - I just needed to switch it to:


Question is, will this then break when I update to a later version of OG after this token business has been fixed?

BTW, if you change a Groups Audience field from accepting multiple values to just a single value, using delta 0 in your token seems to break. I did exactly that and had to change:

[node:og-group-ref:0:nid] to [node:og-group-ref:nid] (removed 0:)

PathAuto was freaking right out until I figured out that I'd have to make that amend. Hope that helps somebody.

Thanks for the heads up, @dixhuit. I'll try to remember that one if I go from multiple=>single!

I was also having hard time getting the groups path as the path prefix for group nodes. here my slight adaptation of og_token.module.

I added the path to the group array and returned it instead of label.

* Implements hook_token_info().
function og_token_token_info() {
$info = array();
$info['tokens']['node']['og-group-audience'] = array(
'name' => t('Group audience labels'),
'description' => t('Outputs the group audience labels of a node.'),
'type' => 'array',
* Implements hook_tokens().
function og_token_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
$join = isset($options['join']) ? $options['join'] : ', ';
// Skip if we are not given a node with a group audience field.
if ($type == 'node' && !empty($data['node']->group_audience)) {
// Loop through the given tokens.
foreach ($tokens as $name => $original) {
      switch (
$name) {
// Avoid loading the labels more than once.
if (!isset($labels)) {
$groups = og_token_get_group_audience_groups($data['node']);
$labels = og_token_get_group_labels($groups, $options);
$replacements[$original] = implode($join, $labels);
// Resolve chained token relationships.
if ($group_audience_tokens = token_find_with_prefix($tokens, 'og-group-audience')) {
      if (!isset(
$labels)) {
$groups = og_token_get_group_audience_groups($data['node']);
$labels = og_token_get_group_labels($groups, $options);
$replacements += token_generate('array', $group_audience_tokens, array('array' => $labels), $options);
* Return the group labels of a given array of groups.
* @param array $groups
*   An array of Organic Group group objects.
* @param array $options
*   An associative array of options for token replacement.
* @return array
*   An array containing the labels of the passed in groups.
function og_token_get_group_labels($groups, $options) {
$labels = array();
$sanitize = !empty($options['sanitize']);
  foreach (
$groups as $group) {
$labels[] = $sanitize ? check_plain($group->path) : $group->path;
* Return the groups that are referenced in the group_audience field of a node.
* @param object $node
*   A node object.
* @return array
*   An array of Organic Group group objects.
function og_token_get_group_audience_groups($node) {
$groups = array();
$group_audiences = field_get_items('node', $node, 'group_audience');
  foreach (
$group_audiences as $group_audience) {
    if (!empty(
$group_audience['gid']) && $group = og_get_group('group', $group_audience['gid'])) {
$gnode = node_load($group_audience['gid']);
$group->path = $gnode->field_group_path['und'][0]['safe_value'];
$groups[] = $group;

Status:Active» Fixed

I think we can close this, as it works fine for me and others (#122).

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Bingo! I was using Custom Breadcrumbs with OG 7.2x and couldn't figure out the tokens. Finally!

Hi Leoklein

I wonder how you succeeded to use the code given in #124, because it uses the concept of OG 7.1 which is completely different from OG 7.2

Anyway, I rewrote the module to make it work with OG 7.2 and tested with success


Thank-you danoguru and lahode. I used lahode's code for OG 7.2 and works like a charm. :-)