From 7cc5305f9cb9a6960c318d76e3499b62d1a41e9e Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 11 Jun 2015 12:25:21 -0400 Subject: [PATCH] CRM-16570 - Fix nesting one menu item into another --- CRM/Core/BAO/Navigation.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) 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; -- 2.25.1