function hreflang_hierarchy_get_links in Language Hierarchy 7
Gets hreflang links for given path.
Parameters
$path: Path used to lookup for hreflang links.
Return value
array Hreflang links.
1 call to hreflang_hierarchy_get_links()
- hreflang_hierarchy_html_head_alter in modules/
hreflang_hierarchy/ hreflang_hierarchy.module - Implements hook_html_head_alter().
File
- modules/
hreflang_hierarchy/ hreflang_hierarchy.module, line 81
Code
function hreflang_hierarchy_get_links($path) {
$languages = language_list('enabled');
$links = array();
// Node entity.
$entity = menu_get_object();
$entity_type = 'node';
// Taxonomy term entity.
if (empty($entity)) {
$entity = menu_get_object('taxonomy_term', 2);
$entity_type = 'taxonomy_term';
}
// User entity.
if (empty($entity)) {
$entity = menu_get_object('user');
$entity_type = 'user';
}
// Entity translation support.
// Entity translation is enabled for loaded entity and it has some translations.
$et_enabled = $entity && module_exists('entity_translation_hierarchy') && entity_translation_enabled($entity_type, $entity);
$has_translation = isset($entity->translations->data);
if ($et_enabled && $has_translation) {
list($entity_id) = entity_extract_ids($entity_type, $entity);
foreach ($languages[1] as $language) {
$language_candidate = entity_translation_hierarchy_get_candidate($entity, $entity_type, $language->language);
if (!entity_translation_hierarchy_is_blocked($entity, $entity_type, $language_candidate) && empty($language->hidden)) {
$links[$language->language] = array(
'href' => $entity_type . '/' . $entity_id,
'object' => $entity->translations->data[$language_candidate],
);
}
}
}
elseif (module_exists('translation') && !empty($entity->tnid)) {
$translations = translation_node_get_translations($entity->tnid);
foreach ($translations as $langcode => $translation) {
if ($langcode != $entity->language && $translation->status && isset($languages[1][$langcode]) && empty($languages[1][$langcode]->hidden)) {
$links[$langcode] = array(
'href' => 'node/' . $translation->nid,
'object' => $translation,
);
}
}
}
else {
foreach ($languages[1] as $language) {
if (empty($language->hidden)) {
$links[$language->language] = array(
'href' => $path,
'title' => $language->native,
);
}
}
}
return $links;
}