Esempio n. 1
0
 /**
  *
  * Create a new nav item with a specific language, title and alias based on a given nav item id.
  * All content of the source nav item will be copied dependent on the nav item type (page content, module link, redirect informations).
  *
  * @param $navItemId source nav item
  * @param $langId (new) target language
  * @param $title title of nav item
  * @param $alias alias of nav item
  * @return bool
  */
 public function createItemLanguageCopy($navItemId, $langId, $title, $alias)
 {
     $sourceNavItem = NavItem::findOne($navItemId);
     if (!$sourceNavItem) {
         return false;
     }
     if (NavItem::find()->where(['nav_id' => $sourceNavItem->nav_id, 'lang_id' => $langId])->one()) {
         return false;
     }
     $navItem = new NavItem();
     $navItem->attributes = $sourceNavItem->toArray();
     $navItem->title = $title;
     $navItem->alias = $alias;
     $navItem->lang_id = $langId;
     $navItem->setParentFromModel();
     if (!$navItem->save()) {
         return false;
     }
     // we have created the copy, but its seems like no version existis for the original to copy page,
     // so we can not copy any content, lets return true and skip copy process.
     if (empty($sourceNavItem->nav_item_type_id)) {
         return true;
     }
     return $sourceNavItem->copyTypeContent($navItem);
 }