function oa_core_tokens in Open Atrium Core 7.2
Implements hook_tokens().
File
- ./
oa_core.module, line 1450
Code
function oa_core_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type == 'node' && !empty($data['node']) && isset($tokens['group-or-section-alias'])) {
$node = $data['node'];
$original = $tokens['group-or-section-alias'];
$section = field_get_items('node', $node, OA_SECTION_FIELD);
$space = field_get_items('node', $node, OA_SPACE_FIELD);
$section_id = !empty($section[0]['target_id']) ? $section[0]['target_id'] : 0;
$space_id = !empty($space[0]['target_id']) ? $space[0]['target_id'] : 0;
$default_path_alias = variable_get('oa_default_path_alias', 'content');
$languagecode = isset($options['language']) ? $options['language']->language : NULL;
if ($section_id && node_load($section_id)) {
$path = drupal_get_path_alias('node/' . $section_id, $languagecode);
if (module_exists('pathauto') && preg_match('#^node/(\\d+)#', $path)) {
// section alias not defined yet, so define it
$path = oa_core_get_alias($section_id, $languagecode);
}
if (!empty($path)) {
$replacements[$original] = $path;
}
}
elseif ($space_id && node_load($space_id)) {
$path = drupal_get_path_alias('node/' . $space_id, $languagecode);
if (module_exists('pathauto') && preg_match('#^node/(\\d+)#', $path)) {
// space alias not defined yet, so define it
$path = oa_core_get_alias($space_id, $languagecode);
}
if (!empty($path)) {
$replacements[$original] = $path;
if ($node->type != OA_SECTION_TYPE) {
$replacements[$original] .= "/{$default_path_alias}";
}
}
}
else {
$replacements[$original] = $default_path_alias;
}
}
return $replacements;
}