You are here

function gathercontent_create_menu_link in GatherContent 7.3

Parameters

$nid:

$title:

$plid:

null $lang:

null $tsid:

1 call to gathercontent_create_menu_link()
_gathercontent_fetcher in ./gathercontent.module
Helper function for fetching data from GatherContent.

File

./gathercontent.module, line 825

Code

function gathercontent_create_menu_link($nid, $title, $plid, $lang = NULL, &$tsid = NULL) {
  $weight = 1;
  if (!empty($plid)) {
    if (is_null($lang) || $lang === LANGUAGE_NONE) {

      // Single language node.
      list($menu_name, $mlid) = explode(':', $plid);
      if ($menu_name === 'node') {
        _gathercontent_get_menu_by_gathercontent_id($mlid, $menu_name);
      }
      $link = array(
        'link_path' => 'node/' . $nid,
        'link_title' => $title,
        'menu_name' => $menu_name,
        'plid' => $mlid,
        'weight' => $weight,
      );
      menu_link_save($link);
    }
    elseif (module_exists('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') {
          _gathercontent_get_menu_by_gathercontent_id($mlid, $menu_name, $lang);
        }
        $link = array(
          'link_path' => 'node/' . $nid,
          'link_title' => $title,
          'menu_name' => $menu_name,
          'plid' => $mlid,
          'weight' => $weight,
          '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') {
          _gathercontent_get_menu_by_gathercontent_id($mlid, $menu_name, $lang);
        }
        elseif ($mlid != 0) {

          // 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();
      }
    }
  }
}