1

I'm trying to create a path alias for a node type, where the first part of the alias is the url path of the organic group. I tried this

[node:og-group-ref:1:url]/[node:content-type]/[node:title]

but it didn't work. When I tried this

[node:og-group-ref]/[node:content-type]/[node:title]

it did create an alias, but [node:og-group-ref] refered to the node title, not the path alias of the node.

From here - https://www.drupal.org/node/2302879 - saw that there are tokens for [node:og-group-ref:url:relative], but thats not a valid token on my site. I am using Organic groups 7.x-2.7.

Is this a possible alias?

0

I'm not sure what the real answer is to this issue, but I found a workaround: I created my own token which provided me this alias

/**
 * Implements hook_token_info().
 */
function example_tokens_token_info() {
  $types['og_path_alias'] = array(
    'name' => t('The OG Path Alias'),
    'description' => t('Tokens for the OG path alias'),
  );
  $og_path_alias['path_alias'] = array(
    'name' => t('The OG Path Alias'),
     'description' => t('The OG path alias'),
  );
  return array(
    'types' => $types,
    'tokens' => array(
      'og_path_alias' => $og_path_alias,
    ),
  );
}

/**
 * Implements hook_tokens().
 */
function example_tokens_tokens($type, $tokens, array $data = array(), array $options =     array()) {
  $replacements = array();

  if($type === 'og_path_alias') {
    $node = $data['node'];
    foreach($tokens as $name=>$original) {
      switch($name) {
      case 'path_alias':
      $node_wrapper = entity_metadata_wrapper('node', $node);
      if($node_wrapper->__isset('og_group_ref')) {
        $chapters = $node_wrapper->og_group_ref->value();
        foreach($chapters as $chapter) {
          $new_alias = drupal_get_path_alias('node/' . $chapter->nid);
        }
      }
      $replacements[$original] = $new_alias;
      break;
  }
}
}

return $replacements;
}
0

The Entity token module, part of Entity API module, can do this for you. it provides token replacements for all properties that have no tokens and are known to the entity API, such as fields within a group tied to a node. e.g [node:og-group-ref:0:field_name_here]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.