Skip to content

Add tab configuration for the EnvSource plugin #299

Merged
merged 1 commit into from Feb 14, 2025
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
Expand Up @@ -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 = [
Expand All @@ -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.
*
Expand Down
23 changes: 23 additions & 0 deletions app/plugins/EnvSource/src/Controller/EnvSourcesController.php
Expand Up @@ -30,11 +30,34 @@
namespace EnvSource\Controller;

use App\Controller\StandardPluginController;
use Cake\Event\EventInterface;
use Cake\Http\Response;

class EnvSourcesController extends StandardPluginController {
public $paginate = [
'order' => [
'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);
}
}
17 changes: 17 additions & 0 deletions app/plugins/EnvSource/src/Model/Table/EnvSourceCollectorsTable.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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',
Expand Down
20 changes: 19 additions & 1 deletion app/plugins/EnvSource/src/Model/Table/EnvSourcesTable.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions app/src/View/Helper/TabHelper.php
Expand Up @@ -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
*
Expand Down
5 changes: 5 additions & 0 deletions app/templates/element/subnavigation/tabList.php
Expand Up @@ -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;
}
}
?>
<!-- if a tab has no fields do not render skip -->
Expand Down