From d592cf4fc9300b2a112a59d966064ee2e1224170 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Wed, 16 Oct 2024 17:00:18 +0300 Subject: [PATCH] Check for hasMany associations before rendering a tab --- .../src/Model/Table/AttributeCollectorsTable.php | 3 +-- app/src/Model/Table/EnrollmentFlowStepsTable.php | 11 ++++------- app/src/View/Helper/TabHelper.php | 2 -- app/templates/element/subnavigation/tabList.php | 14 +++++++++----- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php index e7f74a3e..2c7701b4 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php @@ -89,8 +89,7 @@ public function initialize(array $config): void { 'EnrollmentFlowSteps' => ['edit', 'view'], 'CoreEnroller.AttributeCollectors' => ['edit'], 'CoreEnroller.EnrollmentAttributes' => ['index'], - ], - 'skipTab' => ['CoreEnroller.AttributeCollectors'] + ] ] ); diff --git a/app/src/Model/Table/EnrollmentFlowStepsTable.php b/app/src/Model/Table/EnrollmentFlowStepsTable.php index f48c612b..3cf26d16 100644 --- a/app/src/Model/Table/EnrollmentFlowStepsTable.php +++ b/app/src/Model/Table/EnrollmentFlowStepsTable.php @@ -41,14 +41,14 @@ class EnrollmentFlowStepsTable extends Table { use \App\Lib\Traits\AutoViewVarsTrait; use \App\Lib\Traits\ChangelogBehaviorTrait; use \App\Lib\Traits\CoLinkTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PluggableModelTrait; use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\TabTrait; - use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\TableMetaTrait; use \App\Lib\Traits\ValidationTrait; - + /** * Perform Cake Model initialization. * @@ -142,13 +142,10 @@ public function initialize(array $config): void { 'EnrollmentFlowSteps.Plugin' => ['edit'], // This means that we are looking at the plugins associated model // EnrollmentFlowSteps -> plugin -> @plugin + // XXX There might be plugins that have no hasMany associations. We will check + // for these use cases inside the element. 'EnrollmentFlowSteps.Hierarchy' => ['index'] ], - // For whatever reason, we want to skip a tab from rendering. Here we do not render - // because the configuration has no fields. - // We do not do this dynamically since it is a very rare use case and the table - // has metadata fields. This means that we should filter them out. - 'skipTab' => ['EnrollmentFlowSteps.Plugin'] ] ] ); diff --git a/app/src/View/Helper/TabHelper.php b/app/src/View/Helper/TabHelper.php index b3ddcf29..9bc78da5 100644 --- a/app/src/View/Helper/TabHelper.php +++ b/app/src/View/Helper/TabHelper.php @@ -232,8 +232,6 @@ public function getCurrentId(string $tabName = null, bool $isNested = false): in return (int)$tid; } - - /** * Check the belongsTo tree hierarchy * diff --git a/app/templates/element/subnavigation/tabList.php b/app/templates/element/subnavigation/tabList.php index 03342c97..5edb06e1 100644 --- a/app/templates/element/subnavigation/tabList.php +++ b/app/templates/element/subnavigation/tabList.php @@ -37,16 +37,20 @@ 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; + } } ?>