diff --git a/app/src/Lib/Util/TableUtilities.php b/app/src/Lib/Util/TableUtilities.php index add83efe..c97680cc 100644 --- a/app/src/Lib/Util/TableUtilities.php +++ b/app/src/Lib/Util/TableUtilities.php @@ -145,20 +145,21 @@ public static function treeTraversalFromId(string $modelName, int $id, array &$r // Get the Record from the database $resp = $ModelTable->find() ->where(['id' => $id]) - ->first() - ->toArray(); - - // Find all the foreign keys and fetch the rest of the tree - foreach($resp as $col => $val) { - if ( - $val !== null - && $col !== $modelName - && str_ends_with($col, '_id') - ) { - $fkModel = StringUtilities::foreignKeyToClassName(($col)); - $fk_table = Inflector::underscore($fkModel); - if (\in_array($fk_table, $listOfTables, true)) { - self::treeTraversalFromPrimaryLink($col, $val, $results); + ->first()?->toArray(); + + if ($resp !== null) { + // Find all the foreign keys and fetch the rest of the tree + foreach($resp as $col => $val) { + if ( + $val !== null + && $col !== $modelName + && str_ends_with($col, '_id') + ) { + $fkModel = StringUtilities::foreignKeyToClassName(($col)); + $fk_table = Inflector::underscore($fkModel); + if (\in_array($fk_table, $listOfTables, true)) { + self::treeTraversalFromPrimaryLink($col, $val, $results); + } } } } diff --git a/app/src/View/Helper/TabHelper.php b/app/src/View/Helper/TabHelper.php index 6f4a3022..948094ce 100644 --- a/app/src/View/Helper/TabHelper.php +++ b/app/src/View/Helper/TabHelper.php @@ -186,20 +186,16 @@ public function tabBelongsToModelPath(string $tab, string $modelFullName, int &$ */ public function getCurrentId(string $tabName = null, bool $isNested = false): int { - $vv_person_id = $this->getView()->get('vv_person_id'); $vv_obj = $this->getView()->get('vv_obj'); $vv_primary_link = $this->getView()->get('vv_primary_link'); $vv_bc_title_links = $this->getView()->get('vv_bc_title_links'); $request = $this->getView()->getRequest(); $curController = $request->getParam('controller'); - $curAction = $request->getParam('action'); - $plugin = $this->getView()->getPlugin(); $vv_sub_nav_attributes = $this->getView()->get('vv_sub_nav_attributes'); $tab_actions = !$isNested ? $vv_sub_nav_attributes['action'] : $vv_sub_nav_attributes['nested']['action']; $tabs = !$isNested ? $vv_sub_nav_attributes['tabs'] : $vv_sub_nav_attributes['nested']['tabs']; - $tid = $vv_person_id - ?? $request->getQuery($vv_primary_link) + $tid = $request->getQuery($vv_primary_link) ?? $vv_obj->id ?? end($vv_bc_title_links[0]['target']);