Skip to content

Commit

Permalink
Merge pull request #237 from Ioannis/fix_deep_nested_association_calc…
Browse files Browse the repository at this point in the history
…ulation

Fix use case:Plugin.Hierarchy deep nested when no hasMany association.
  • Loading branch information
Ioannis authored Oct 15, 2024
2 parents 5c52be2 + 1008163 commit 59e1267
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
13 changes: 9 additions & 4 deletions app/src/View/Helper/TabHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
14 changes: 13 additions & 1 deletion app/templates/element/subnavigation/inlineList.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,21 @@
?>

<?php foreach($vv_subnavigation_nested['tabs'] as $tab): ?>
<?php
// calculate the id
$curId = $this->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;
}
}

?>
<li class="list-inline-item">
<?php
$curId = $this->Tab->getCurrentId($tab, $isNested);
// Construct Element Title
$title = $this->element('subnavigation/tabTitle', compact('tab', 'curId', 'isNested'));
// Construct Target URL
Expand Down

0 comments on commit 59e1267

Please sign in to comment.