function gc_create_menu_link in GatherContent 8
Same name and namespace in other branches
- 8.3 gathercontent.module \gc_create_menu_link()
Parameters
\EntityMetadataWrapper $node:
$field:
$plid:
1 call to gc_create_menu_link()
File
- ./
gathercontent.module, line 291 - Main module file for GatherContent module.
Code
function gc_create_menu_link($nid, $title, $plid, $lang = NULL, &$tsid = NULL) {
if (!empty($plid)) {
if (is_null($lang)) {
// Single language node.
list($menu_name, $mlid) = explode(':', $plid);
if ($menu_name === 'node') {
_gc_get_menu_by_gc_id($mlid, $menu_name);
}
$link = array(
'link_path' => 'node/' . $nid,
'link_title' => $title,
'menu_name' => $menu_name,
'plid' => $mlid,
);
menu_link_save($link);
}
elseif (\Drupal::moduleHandler()
->moduleExists('i18n_menu')) {
if (!is_null($lang) && is_null($tsid)) {
// Multi language node - first language.
$menu_translation_set = i18n_translation_set_create('menu_link');
list($menu_name, $mlid) = explode(':', $plid);
if ($menu_name === 'node') {
_gc_get_menu_by_gc_id($mlid, $menu_name, $lang);
}
$link = array(
'link_path' => 'node/' . $nid,
'link_title' => $title,
'menu_name' => $menu_name,
'plid' => $mlid,
'language' => $lang,
);
menu_link_save($link);
$menu_translation_set
->add_item($link);
$menu_translation_set
->save_translations();
$tsid = $menu_translation_set->tsid;
}
elseif (!is_null($lang) && !is_null($tsid)) {
// Multi language node - other language.
$menu_translation_set = i18n_translation_set_load($tsid);
list($menu_name, $mlid) = explode(':', $plid);
if ($menu_name === 'node') {
_gc_get_menu_by_gc_id($mlid, $menu_name, $lang);
}
else {
// Load parent translation.
$item = menu_link_load($mlid);
$translation_set = i18n_translation_set_load($item['i18n_tsid']);
$translations = $translation_set
->get_translations();
$mlid = $translations[$lang]['mlid'];
}
$link = array(
'link_path' => 'node/' . $nid,
'link_title' => $title,
'menu_name' => $menu_name,
'plid' => $mlid,
'language' => $lang,
);
menu_link_save($link);
$menu_translation_set
->add_item($link);
$menu_translation_set
->save_translations();
}
}
}
}