From b8915f77baf20fc3ae6a66d45cf90a1e5c2f96e0 Mon Sep 17 00:00:00 2001 From: Marton Kiss Date: Fri, 9 Jan 2015 20:21:02 +0100 Subject: [PATCH] Fix url aliases of group content types Backport node:commons-groups-first-group token from Commons 7.20 to correctly insert the group name into a group content url. This part was broken in Commons 7.15. Change-Id: Iaf3e38186200384cc3624461078ecd65342ff29f --- .../commons_groups/commons_groups.module | 24 +++++++++++++++++++ .../commons_groups.strongarm.inc | 2 +- .../commons_q_a/commons_q_a.strongarm.inc | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/modules/commons/commons_groups/commons_groups.module b/modules/commons/commons_groups/commons_groups.module index 876e941..cf535a3 100644 --- a/modules/commons/commons_groups/commons_groups.module +++ b/modules/commons/commons_groups/commons_groups.module @@ -508,6 +508,10 @@ function commons_groups_token_info() { 'name' => t('"In groups" text'), 'description' => t('The text (starting with "in the groups") indicating which groups a peice of content belongs to.'), ); + $tokens['node']['commons-groups-first-group'] = array( + 'name' => t('First Group'), + 'description' => t('First group associated with a piece of content. Useful for path aliases'), + ); $tokens['node']['commons-groups-group-contributors-count-topics'] = array( 'name' => t('Commons Groups: Group contributor count and topics'), 'description' => t('Displays text showing the number of contributors and the topics associated with a group node.'), @@ -578,6 +582,26 @@ function commons_groups_tokens($type, $tokens, $data = array(), $options = array return $replacements; } } + if ($type == 'node' && !empty($data['node'])) { + if (!empty($tokens['commons-groups-first-group'])) { + $group = $data['node']; + $text = ''; + + if (!empty($group->og_group_ref[LANGUAGE_NONE])) { + $wrapper = entity_metadata_wrapper('node', $group); + $groups = $wrapper->og_group_ref->value(); + + // Return the title of the first group associated with this node. + $first_group = array_shift($groups); + + // Use the title field by default and fall back to the node title. + $first_group_wrapper = entity_metadata_wrapper('node', $first_group); + $text = isset($first_group_wrapper->title_field) ? $first_group_wrapper->title_field->value() : $first_group_wrapper->label(); + } + $replacements['[node:commons-groups-first-group]'] = $text; + return $replacements; + } + } } function commons_groups_message_partial_default() { diff --git a/modules/commons/commons_groups/commons_groups.strongarm.inc b/modules/commons/commons_groups/commons_groups.strongarm.inc index 42321f3..6ee80e8 100644 --- a/modules/commons/commons_groups/commons_groups.strongarm.inc +++ b/modules/commons/commons_groups/commons_groups.strongarm.inc @@ -172,7 +172,7 @@ function commons_groups_strongarm() { $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ $strongarm->api_version = 1; $strongarm->name = 'pathauto_node_pattern'; - $strongarm->value = 'groups/[node:og-group-ref:0:title]/[node:title]'; + $strongarm->value = 'groups/[node:commons-groups-first-group]/[node:title]'; $export['pathauto_node_pattern'] = $strongarm; return $export; diff --git a/modules/commons/commons_q_a/commons_q_a.strongarm.inc b/modules/commons/commons_q_a/commons_q_a.strongarm.inc index f800d2b..82c0d25 100644 --- a/modules/commons/commons_q_a/commons_q_a.strongarm.inc +++ b/modules/commons/commons_q_a/commons_q_a.strongarm.inc @@ -323,7 +323,7 @@ function commons_q_a_strongarm() { $strongarm->disabled = FALSE; /* Edit this to true to make a default strongarm disabled initially */ $strongarm->api_version = 1; $strongarm->name = "pathauto_node_answer_pattern"; - $strongarm->value = 'groups/[node:og-group-ref:0:title-field]/[node:field-related-question:title-field]/[node:title-field]'; + $strongarm->value = 'groups/[node:commons-groups-first-group]/[node:field-related-question:title-field]/[node:title-field]'; $export["pathauto_node_answer_pattern"] = $strongarm; return $export;