diff --git a/app/plugins/EnvSource/resources/locales/en_US/env_source.po b/app/plugins/EnvSource/resources/locales/en_US/env_source.po index 2cf309708..bf902af83 100644 --- a/app/plugins/EnvSource/resources/locales/en_US/env_source.po +++ b/app/plugins/EnvSource/resources/locales/en_US/env_source.po @@ -31,6 +31,9 @@ msgstr "{0,plural,=1{Env Source} other{Env Sources}}" msgid "controller.PetitionEnvIdentities" msgstr "{0,plural,=1{Petition Env Identity} other{Petition Env Identities}}" +msgid "display.EnvSource" +msgstr "{0} Source" + msgid "enumeration.EnvSourceSpModeEnum.O" msgstr "Other" diff --git a/app/plugins/EnvSource/src/Model/Table/EnvSourcesTable.php b/app/plugins/EnvSource/src/Model/Table/EnvSourcesTable.php index 48e62f736..398a231eb 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\QueryModificationTrait; use \App\Lib\Traits\TabTrait; use \App\Lib\Traits\TableMetaTrait; use \App\Lib\Traits\ValidationTrait; @@ -97,6 +98,14 @@ public function initialize(array $config): void { $this->setPrimaryLink(['external_identity_source_id']); $this->setRequiresCO(true); + $this->setEditContains([ + 'ExternalIdentitySources', + ]); + + $this->setViewContains([ + 'ExternalIdentitySources', + ]); + // All the tabs share the same configuration in the ModelTable file $this->setTabsConfig( [ @@ -156,6 +165,17 @@ public function initialize(array $config): void { ]); } + /** + * Table specific logic to generate a display field. + * + * @since COmanage Registry v5.2.0 + * @param \EnvSource\Model\Entity\EnvSource $entity Entity to generate display field for + * @return string Display field + */ + public function generateDisplayField(\EnvSource\Model\Entity\EnvSource $entity): string { + return __d('env_source', 'display.EnvSource', [$entity->external_identity_source->description]); + } + /** * Obtain the set of changed records from the source database. * diff --git a/app/src/Controller/Component/BreadcrumbComponent.php b/app/src/Controller/Component/BreadcrumbComponent.php index 903c47898..5bb54af8a 100644 --- a/app/src/Controller/Component/BreadcrumbComponent.php +++ b/app/src/Controller/Component/BreadcrumbComponent.php @@ -227,7 +227,8 @@ public function injectPrimaryLink(object $link, bool $index = true, string $link ); return $canEdit ? 'edit' : ($canView ? 'view' : ''); - } + }, + forChainItem: true ); $linkTable = \Cake\ORM\TableRegistry::getTableLocator()->get($linkModelFqn); @@ -391,6 +392,7 @@ private function resolveContainList($table, string $mappedAction): array * @param int|null $currentId Current entity ID * @param array $pagePermissions Permissions for the current page * @param callable $peopleActionOverride Override callback for People actions + * @param bool $forChainItem Explicit call for a chain item (e.g. add) * @return string Mapped action name * @since COmanage Registry v5.2.0 */ @@ -398,23 +400,30 @@ private function mapActionForBreadcrumb( string $requestAction, ?int $currentId, array $pagePermissions, - callable $peopleActionOverride + callable $peopleActionOverride, + bool $forChainItem ): string { - // Custom override for People if provided $override = $peopleActionOverride(); if ($override !== '') { return $override; } - if (in_array($requestAction, ['index', 'view', 'delete', 'add', 'edit'], true)) { - return $requestAction; - } - - if ($currentId !== null) { - return (!empty($pagePermissions['edit'])) ? 'edit' : 'view'; + if ($forChainItem) { + // Never render 'add' for chain items + if ($requestAction === 'add') { + return 'index'; + } + // If the current page is edit/view/delete (and thus has an entity), prefer edit/view + if (in_array($requestAction, ['edit', 'view', 'delete'], true) && $currentId !== null) { + return (!empty($pagePermissions['edit'])) ? 'edit' : 'view'; + } + return in_array($requestAction, ['index', 'view', 'delete', 'edit'], true) + ? $requestAction + : 'index'; } - return 'index'; + // If you ever reuse this for non-chain items, decide appropriate behavior here + return $requestAction; } /** @@ -427,15 +436,17 @@ private function mapActionForBreadcrumb( */ private function determineEntityAction($entity, string $mappedAction): string { - if ($mappedAction === 'add' || $mappedAction === 'delete') { - return $mappedAction; + // Only allow 'delete' to pass through; never return 'add' for existing entities + if ($mappedAction === 'delete') { + return 'delete'; } if (method_exists($entity, 'isReadOnly')) { return $entity->isReadOnly() ? 'view' : 'edit'; } - return $mappedAction; + // Fall back to mapped action when not 'add'/'delete' + return $mappedAction === 'add' ? 'view' : $mappedAction; } /**