Skip to content

Fix use case:Plugin.Hierarchy deep nested when no hasMany association. #237

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions app/src/View/Helper/TabHelper.php
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
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