diff --git a/og.tokens.inc b/og.tokens.inc index 9d74950..a5963d2 100644 --- a/og.tokens.inc +++ b/og.tokens.inc @@ -15,12 +15,6 @@ function og_token_info() { 'needs-data' => 'group', ); - $types['group-manager'] = array( - 'name' => t('Group manager'), - 'description' => t('Tokens related to the group manager user.'), - 'type' => 'user', - ); - $group['gid'] = array( 'name' => t('Group ID'), 'description' => t("The unique ID of the group."), @@ -42,6 +36,18 @@ function og_token_info() { 'type' => 'date', ); + $group['node'] = array( + 'name' => t('Main group node'), + 'description' => t('The main node that identifies this group.'), + 'type' => 'node', + ); + + $group['manager'] = array( + 'name' => t('Manager user'), + 'description' => t('Tokens related to the group manager user.'), + 'type' => 'user', + ); + return array( 'types' => $types, 'tokens' => array('group' => $group), @@ -76,6 +82,7 @@ function og_tokens($type, $tokens, array $data = array(), array $options = array $replacements[$original] = og_label($group->gid, $sanitize); break; + case 'node': case 'url': $entity = $group->getEntity(); $uri = entity_uri($group->entity_type, $entity); @@ -86,16 +93,47 @@ function og_tokens($type, $tokens, array $data = array(), array $options = array // In the case of user_presave the created date may not yet be set. $replacements[$original] = !empty($group->created) ? format_date($group->created, 'medium', '', NULL, $language_code) : t('not yet created'); break; + + case 'manager': + if($group->entity_type == "node") { + if(($entity = $group->getEntity()) && ($account = user_load($entity->uid))) { + $replacements[$original] = $sanitize ? check_plain($account->name) : $account->name; + } + } + break; + } } if ($registered_tokens = token_find_with_prefix($tokens, 'created')) { $replacements += token_generate('date', $registered_tokens, array('date' => $account->created), $options); } - } - if ($type == 'group-manager' && !empty($data['group-manager'])) { - $replacements += token_generate('user', $tokens, array('user' => $data['group-manager']), $options); + if ($node_tokens = token_find_with_prefix($tokens, 'node')) { + if ($group->entity_type == "node") { + if ($entity = $group->getEntity()) { + $replacements += token_generate('node', $node_tokens, array('node' => $entity), $options); + } + } + else { + foreach ($tokens as $name => $original) { + $replacements[$original] = t('group entity not a node'); + } + } + } + + if ($node_tokens = token_find_with_prefix($tokens, 'manager')) { + if ($group->entity_type == "node") { + if (($entity = $group->getEntity()) && ($account = user_load($entity->uid))) { + $replacements += token_generate('user', $node_tokens, array('user' => $account), $options); + } + } + else { + foreach ($tokens as $name => $original) { + $replacements[$original] = t('group entity not a node'); + } + } + } } return $replacements; diff --git a/og_context/og_context.tokens.inc b/og_context/og_context.tokens.inc new file mode 100644 index 0000000..893d37e --- /dev/null +++ b/og_context/og_context.tokens.inc @@ -0,0 +1,37 @@ + t('Current group'), + 'description' => t('Tokens related to the current group as found via OG\'s context module settings.'), + 'type' => 'group', + ); + + return array( + 'types' => $types, + ); +} + +/** + * Implements hook_tokens(). + */ +function og_context_tokens($type, $tokens, array $data = array(), array $options = array()) { + $replacements = array(); + + if ($type == 'current-group') { + if ($group = og_context()) { + $replacements += token_generate('group', $tokens, array('group' => $group), $options); + } + } + + return $replacements; +} +