From 10081635f05defaebc0f5f74ac129bb307438832 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Tue, 15 Oct 2024 11:28:06 +0300 Subject: [PATCH] Fix use case:Plugin.Hierarchy deep nested when no hasMany association. --- app/src/View/Helper/TabHelper.php | 13 +++++++++---- app/templates/element/subnavigation/inlineList.php | 14 +++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/src/View/Helper/TabHelper.php b/app/src/View/Helper/TabHelper.php index 23b6adc1..b3ddcf29 100644 --- a/app/src/View/Helper/TabHelper.php +++ b/app/src/View/Helper/TabHelper.php @@ -245,11 +245,16 @@ public function getCurrentId(string $tabName = null, bool $isNested = false): in public function getHasManyAssociationModels(string $modelName): \Generator { $model = TableRegistry::getTableLocator()->get($modelName); - // We'll start by obtaining the set of models directly associated with the CO model. - $associations = $model->associations(); + // We'll start by getting the set of models directly associated with the CO model. + $associations = $model->associations()->getByType(['hasMany', 'hasOne']); + + if(empty($associations)) { + // Yield null if empty + yield; + } - foreach($associations->getByType(['hasMany', 'hasOne']) as $ta) { - $this>$this->setAssociation($ta->getClassName()); + foreach($associations as $ta) { + $this->setAssociation($ta->getClassName()); yield $ta->getClassName(); } } diff --git a/app/templates/element/subnavigation/inlineList.php b/app/templates/element/subnavigation/inlineList.php index 9a3d38d6..6fb1ef48 100644 --- a/app/templates/element/subnavigation/inlineList.php +++ b/app/templates/element/subnavigation/inlineList.php @@ -36,9 +36,21 @@ ?> + Tab->getCurrentId($tab, $isNested); + // Check if there are child models. If not continue + if (str_contains($tab, '.Hierarchy')) { + $modelName = $this->Tab->retrievePluginName($tab, (int)$curId); + [$plugin, ] = explode('.', $modelName); + if($this->Tab->getHasManyAssociationModels($modelName)->current() === null) { + continue; + } + } + + ?>
  • Tab->getCurrentId($tab, $isNested); // Construct Element Title $title = $this->element('subnavigation/tabTitle', compact('tab', 'curId', 'isNested')); // Construct Target URL