From 833d5fa09d42b780c0ec1eb1c81b0a89e11c776c Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Fri, 14 Feb 2025 20:01:21 +0200 Subject: [PATCH] Add tab configuration for the EnvSource plugin --- .../EnvSourceCollectorsController.php | 25 ++++++++++++++++++- .../src/Controller/EnvSourcesController.php | 23 +++++++++++++++++ .../Model/Table/EnvSourceCollectorsTable.php | 17 +++++++++++++ .../src/Model/Table/EnvSourcesTable.php | 20 ++++++++++++++- app/src/View/Helper/TabHelper.php | 21 ++++++++++++++++ .../element/subnavigation/tabList.php | 5 ++++ 6 files changed, 109 insertions(+), 2 deletions(-) diff --git a/app/plugins/EnvSource/src/Controller/EnvSourceCollectorsController.php b/app/plugins/EnvSource/src/Controller/EnvSourceCollectorsController.php index 2383f3df..167b8ef2 100644 --- a/app/plugins/EnvSource/src/Controller/EnvSourceCollectorsController.php +++ b/app/plugins/EnvSource/src/Controller/EnvSourceCollectorsController.php @@ -29,9 +29,11 @@ namespace EnvSource\Controller; -use Cake\ORM\TableRegistry; use App\Controller\StandardEnrollerController; use App\Lib\Enum\PetitionActionEnum; +use Cake\Event\EventInterface; +use Cake\Http\Response; +use Cake\ORM\TableRegistry; class EnvSourceCollectorsController extends StandardEnrollerController { public $paginate = [ @@ -40,6 +42,27 @@ class EnvSourceCollectorsController extends StandardEnrollerController { ] ]; + /** + * Callback run prior to the request render. + * + * @param EventInterface $event Cake Event + * + * @return Response|void + * @since COmanage Registry v5.1.0 + */ + + public function beforeRender(EventInterface $event) { + $link = $this->getPrimaryLink(true); + + if(!empty($link->value)) { + $this->set('vv_bc_parent_obj', $this->EnvSourceCollectors->EnrollmentFlowSteps->get($link->value)); + $this->set('vv_bc_parent_displayfield', $this->EnvSourceCollectors->EnrollmentFlowSteps->getDisplayField()); + $this->set('vv_bc_parent_primarykey', $this->EnvSourceCollectors->EnrollmentFlowSteps->getPrimaryKey()); + } + + return parent::beforeRender($event); + } + /** * Dispatch an Enrollment Flow Step. * diff --git a/app/plugins/EnvSource/src/Controller/EnvSourcesController.php b/app/plugins/EnvSource/src/Controller/EnvSourcesController.php index 663448a4..81d6dd22 100644 --- a/app/plugins/EnvSource/src/Controller/EnvSourcesController.php +++ b/app/plugins/EnvSource/src/Controller/EnvSourcesController.php @@ -30,6 +30,8 @@ namespace EnvSource\Controller; use App\Controller\StandardPluginController; +use Cake\Event\EventInterface; +use Cake\Http\Response; class EnvSourcesController extends StandardPluginController { public $paginate = [ @@ -37,4 +39,25 @@ class EnvSourcesController extends StandardPluginController { 'EnvSources.id' => 'asc' ] ]; + + /** + * Callback run prior to the request render. + * + * @param EventInterface $event Cake Event + * + * @return Response|void + * @since COmanage Registry v5.1.0 + */ + + public function beforeRender(EventInterface $event) { + $link = $this->getPrimaryLink(true); + + if(!empty($link->value)) { + $this->set('vv_bc_parent_obj', $this->EnvSources->ExternalIdentitySources->get($link->value)); + $this->set('vv_bc_parent_displayfield', $this->EnvSources->ExternalIdentitySources->getDisplayField()); + $this->set('vv_bc_parent_primarykey', $this->EnvSources->ExternalIdentitySources->getPrimaryKey()); + } + + return parent::beforeRender($event); + } } diff --git a/app/plugins/EnvSource/src/Model/Table/EnvSourceCollectorsTable.php b/app/plugins/EnvSource/src/Model/Table/EnvSourceCollectorsTable.php index 3741d559..0af822f6 100644 --- a/app/plugins/EnvSource/src/Model/Table/EnvSourceCollectorsTable.php +++ b/app/plugins/EnvSource/src/Model/Table/EnvSourceCollectorsTable.php @@ -47,6 +47,7 @@ class EnvSourceCollectorsTable extends Table { use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\TableMetaTrait; use \App\Lib\Traits\ValidationTrait; + use \App\Lib\Traits\TabTrait; /** * Perform Cake Model initialization. @@ -79,6 +80,22 @@ public function initialize(array $config): void { $this->setRequiresCO(true); $this->setAllowLookupPrimaryLink(['dispatch', 'display']); + // All the tabs share the same configuration in the ModelTable file + $this->setTabsConfig( + [ + // Ordered list of Tabs + 'tabs' => ['EnrollmentFlowSteps', 'EnvSource.EnvSourceCollectors'], + // What actions will include the subnavigation header + 'action' => [ + // If a model renders in a subnavigation mode in edit/view mode, it cannot + // render in index mode for the same use case/context + // XXX edit should go first. + 'EnrollmentFlowSteps' => ['edit', 'view'], + 'EnvSource.EnvSourceCollectors' => ['edit'], + ] + ] + ); + $this->setAutoViewVars([ 'externalIdentitySources' => [ 'type' => 'select', diff --git a/app/plugins/EnvSource/src/Model/Table/EnvSourcesTable.php b/app/plugins/EnvSource/src/Model/Table/EnvSourcesTable.php index 0b8871ab..64383a66 100644 --- a/app/plugins/EnvSource/src/Model/Table/EnvSourcesTable.php +++ b/app/plugins/EnvSource/src/Model/Table/EnvSourcesTable.php @@ -40,6 +40,7 @@ class EnvSourcesTable extends Table { use \App\Lib\Traits\LabeledLogTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; + use \App\Lib\Traits\TabTrait; use \App\Lib\Traits\TableMetaTrait; use \App\Lib\Traits\ValidationTrait; @@ -95,7 +96,24 @@ public function initialize(array $config): void { $this->setPrimaryLink(['external_identity_source_id']); $this->setRequiresCO(true); - + + // All the tabs share the same configuration in the ModelTable file + $this->setTabsConfig( + [ + // Ordered list of Tabs + 'tabs' => ['ExternalIdentitySources', 'EnvSource.EnvSources', 'ExternalIdentitySources@action.search'], + // What actions will include the subnavigation header + 'action' => [ + // If a model renders in a subnavigation mode in edit/view mode, it cannot + // render in index mode for the same use case/context + // XXX edit should go first. + 'ExternalIdentitySources' => ['edit', 'view', 'search'], + 'EnvSource.EnvSources' => ['edit'], + 'ExternalIdentitySources@action.search' => [], + ], + ] + ); + $this->setAutoViewVars([ 'addressTypes' => [ 'type' => 'type', diff --git a/app/src/View/Helper/TabHelper.php b/app/src/View/Helper/TabHelper.php index 71f31429..678f8009 100644 --- a/app/src/View/Helper/TabHelper.php +++ b/app/src/View/Helper/TabHelper.php @@ -311,6 +311,27 @@ public function getHasManyAssociationModels(string $modelName): \Generator } } + + /** + * Check if a specified model supports the 'view' functionality. + * + * This method determines whether a given model is capable of handling + * auto view variable population by checking for the existence of the + * `getAutoViewVars` method and its return value. + * + * @param string $modelName The name of the model to check. + * + * @return bool Returns true if the model supports 'view', otherwise false. + * @since COmanage Registry v5.1.0 + * @note Usually a table will expose AutoViewVars. This is not guaranteed though. + * Revisit if we come across a use case that required more fine-grained check. + */ + public function modelSupportsView(string $modelName): bool + { + $table = TableRegistry::getTableLocator()->get($modelName); + return method_exists($table, 'getAutoViewVars') && $table->getAutoViewVars(); + } + /** * Construct the link filter * diff --git a/app/templates/element/subnavigation/tabList.php b/app/templates/element/subnavigation/tabList.php index 5edb06e1..58e1791d 100644 --- a/app/templates/element/subnavigation/tabList.php +++ b/app/templates/element/subnavigation/tabList.php @@ -46,6 +46,11 @@ if($this->Tab->getHasManyAssociationModels($modelName)->current() === null) { continue; } + // Check if a view is supported + $className = $this->Tab->getHasManyAssociationModels($modelName)->current(); + if (!$this->Tab->modelSupportsView($className)) { + continue; + } } ?>