From: Coleman Watts Date: Thu, 11 Jun 2015 16:25:21 +0000 (-0400) Subject: CRM-16570 - Fix nesting one menu item into another X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7cc5305f9cb9a6960c318d76e3499b62d1a41e9e;p=civicrm-core.git CRM-16570 - Fix nesting one menu item into another --- diff --git a/CRM/Core/BAO/Navigation.php b/CRM/Core/BAO/Navigation.php index d02f1ec3ec..135fa1cf5b 100644 --- a/CRM/Core/BAO/Navigation.php +++ b/CRM/Core/BAO/Navigation.php @@ -748,13 +748,19 @@ ORDER BY parent_id, weight"; // this means node is moved to last position, so you need to get the weight of last element + 1 if (!$newWeight) { - $lastPosition = $position - 1; - $sql = "SELECT weight from civicrm_navigation WHERE {$parentClause} ORDER BY weight LIMIT %1, 1"; - $params = array(1 => array($lastPosition, 'Positive')); - $newWeight = CRM_Core_DAO::singleValueQuery($sql, $params); - - // since last node increment + 1 - $newWeight = $newWeight + 1; + // If this is not the first item being added to a parent + if ($position) { + $lastPosition = $position - 1; + $sql = "SELECT weight from civicrm_navigation WHERE {$parentClause} ORDER BY weight LIMIT %1, 1"; + $params = array(1 => array($lastPosition, 'Positive')); + $newWeight = CRM_Core_DAO::singleValueQuery($sql, $params); + + // since last node increment + 1 + $newWeight = $newWeight + 1; + } + else { + $newWeight = '0'; + } // since this is a last node we don't need to increment other nodes $incrementOtherNodes = FALSE;