diff --git a/og.tokens.inc b/og.tokens.inc index 73f21c3..48d6d83 100644 --- a/og.tokens.inc +++ b/og.tokens.inc @@ -75,7 +75,9 @@ function og_tokens($type, $tokens, array $data = array(), array $options = array switch ($name) { // Basic user account information. case 'gid': - $replacements[$original] = !empty($group->gid) ? $group->gid : t('not yet assigned'); + if(!empty($group->gid)) { + $replacements[$original] = $group->gid; + } break; case 'label': @@ -84,14 +86,16 @@ function og_tokens($type, $tokens, array $data = array(), array $options = array case 'node': case 'url': - $entity = $group->getEntity(); - $uri = entity_uri($group->entity_type, $entity); - $replacements[$original] = !empty($uri['path']) ? url($uri['path'], $url_options) : t('not yet assigned'); + if (($entity = $group->getEntity()) && ($uri = entity_uri($group->entity_type, $entity)) && !empty($uri['path'])) { + $replacements[$original] = url($uri['path'], $url_options); + } break; case 'created': // 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'); + if (!empty($group->created)) { + $replacements[$original] = format_date($group->created, 'medium', '', NULL, $language_code); + } break; case 'manager': @@ -100,9 +104,6 @@ function og_tokens($type, $tokens, array $data = array(), array $options = array $replacements[$original] = $sanitize ? check_plain($account->name) : $account->name; } } - else { - $replacements[$original] = t('group entity is not a node'); - } break; } @@ -112,30 +113,18 @@ function og_tokens($type, $tokens, array $data = array(), array $options = array $replacements += token_generate('date', $registered_tokens, array('date' => $account->created), $options); } - if ($node_tokens = token_find_with_prefix($tokens, 'node')) { - if ($group->entity_type == "node") { + if ($group->entity_type == "node") { + if ($node_tokens = token_find_with_prefix($tokens, '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 is not a node'); - } - } - } - if ($node_tokens = token_find_with_prefix($tokens, 'manager')) { - if ($group->entity_type == "node") { + if ($node_tokens = token_find_with_prefix($tokens, 'manager')) { 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 is not a node'); - } - } } }