From f3ea3e8f9cf4dcdb49634d323c1a511c0f7555cc Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Thu, 18 Sep 2025 20:21:27 +0300 Subject: [PATCH 1/3] Move vv_bc_parent_* calculation in StandardEnrollerController --- .../AttributeCollectorsController.php | 21 ------------------- .../BasicAttributeCollectorsController.php | 21 ------------------- .../Controller/EmailVerifiersController.php | 8 ------- .../EnrollmentAttributesController.php | 8 ------- .../IdentifierCollectorsController.php | 21 ------------------- .../InvitationAcceptersController.php | 21 ------------------- .../Controller/StandardEnrollerController.php | 11 ++++++++++ 7 files changed, 11 insertions(+), 100 deletions(-) diff --git a/app/plugins/CoreEnroller/src/Controller/AttributeCollectorsController.php b/app/plugins/CoreEnroller/src/Controller/AttributeCollectorsController.php index aeb0fb6a9..e9640bd71 100644 --- a/app/plugins/CoreEnroller/src/Controller/AttributeCollectorsController.php +++ b/app/plugins/CoreEnroller/src/Controller/AttributeCollectorsController.php @@ -41,27 +41,6 @@ class AttributeCollectorsController extends StandardEnrollerController { ] ]; - /** - * Callback run prior to the request render. - * - * @param EventInterface $event Cake Event - * - * @return Response|void - * @since COmanage Registry v5.0.0 - */ - - public function beforeRender(EventInterface $event) { - $link = $this->getPrimaryLink(true); - - if(!empty($link->value)) { - $this->set('vv_bc_parent_obj', $this->AttributeCollectors->EnrollmentFlowSteps->get($link->value)); - $this->set('vv_bc_parent_displayfield', $this->AttributeCollectors->EnrollmentFlowSteps->getDisplayField()); - $this->set('vv_bc_parent_primarykey', $this->AttributeCollectors->EnrollmentFlowSteps->getPrimaryKey()); - } - - return parent::beforeRender($event); - } - /** * Dispatch an Enrollment Flow Step. * diff --git a/app/plugins/CoreEnroller/src/Controller/BasicAttributeCollectorsController.php b/app/plugins/CoreEnroller/src/Controller/BasicAttributeCollectorsController.php index be85918ad..4e3496057 100644 --- a/app/plugins/CoreEnroller/src/Controller/BasicAttributeCollectorsController.php +++ b/app/plugins/CoreEnroller/src/Controller/BasicAttributeCollectorsController.php @@ -39,27 +39,6 @@ class BasicAttributeCollectorsController 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(\Cake\Event\EventInterface $event) { - $link = $this->getPrimaryLink(true); - - if(!empty($link->value)) { - $this->set('vv_bc_parent_obj', $this->BasicAttributeCollectors->EnrollmentFlowSteps->get($link->value)); - $this->set('vv_bc_parent_displayfield', $this->BasicAttributeCollectors->EnrollmentFlowSteps->getDisplayField()); - $this->set('vv_bc_parent_primarykey', $this->BasicAttributeCollectors->EnrollmentFlowSteps->getPrimaryKey()); - } - - return parent::beforeRender($event); - } - /** * Dispatch an Enrollment Flow Step. * diff --git a/app/plugins/CoreEnroller/src/Controller/EmailVerifiersController.php b/app/plugins/CoreEnroller/src/Controller/EmailVerifiersController.php index 2922f0c67..6e683e9f9 100644 --- a/app/plugins/CoreEnroller/src/Controller/EmailVerifiersController.php +++ b/app/plugins/CoreEnroller/src/Controller/EmailVerifiersController.php @@ -58,14 +58,6 @@ class EmailVerifiersController extends StandardEnrollerController { */ public function beforeRender(\Cake\Event\EventInterface $event) { - $link = $this->getPrimaryLink(true); - - if(!empty($link->value)) { - $this->set('vv_bc_parent_obj', $this->EmailVerifiers->EnrollmentFlowSteps->get($link->value)); - $this->set('vv_bc_parent_displayfield', $this->EmailVerifiers->EnrollmentFlowSteps->getDisplayField()); - $this->set('vv_bc_parent_primarykey', $this->EmailVerifiers->EnrollmentFlowSteps->getPrimaryKey()); - } - // We use the viewvar to determine the op since 'index' isn't always present $op = $this->viewBuilder()->getVar('vv_op'); diff --git a/app/plugins/CoreEnroller/src/Controller/EnrollmentAttributesController.php b/app/plugins/CoreEnroller/src/Controller/EnrollmentAttributesController.php index fc7198367..b86691aeb 100644 --- a/app/plugins/CoreEnroller/src/Controller/EnrollmentAttributesController.php +++ b/app/plugins/CoreEnroller/src/Controller/EnrollmentAttributesController.php @@ -51,14 +51,6 @@ class EnrollmentAttributesController extends StandardEnrollerController { public function beforeRender(\Cake\Event\EventInterface $event) { $this->set('vv_supported_attributes', $this->EnrollmentAttributes->supportedAttributes()); - $link = $this->getPrimaryLink(true); - - if(!empty($link->value)) { - $this->set('vv_bc_parent_obj', $this->EnrollmentAttributes->AttributeCollectors->get($link->value)); - $this->set('vv_bc_parent_displayfield', $this->EnrollmentAttributes->AttributeCollectors->getDisplayField()); - $this->set('vv_bc_parent_primarykey', $this->EnrollmentAttributes->AttributeCollectors->getPrimaryKey()); - } - $ret = parent::beforeRender($event); $attributes = $this->viewBuilder()->getVar('attributes'); diff --git a/app/plugins/CoreEnroller/src/Controller/IdentifierCollectorsController.php b/app/plugins/CoreEnroller/src/Controller/IdentifierCollectorsController.php index 74347f02e..0a532ecb3 100644 --- a/app/plugins/CoreEnroller/src/Controller/IdentifierCollectorsController.php +++ b/app/plugins/CoreEnroller/src/Controller/IdentifierCollectorsController.php @@ -38,27 +38,6 @@ class IdentifierCollectorsController extends StandardEnrollerController { 'IdentifierCollectors.id' => 'asc' ] ]; - - /** - * Callback run prior to the request render. - * - * @param EventInterface $event Cake Event - * - * @return Response|void - * @since COmanage Registry v5.0.0 - */ - - public function beforeRender(\Cake\Event\EventInterface $event) { - $link = $this->getPrimaryLink(true); - - if(!empty($link->value)) { - $this->set('vv_bc_parent_obj', $this->IdentifierCollectors->EnrollmentFlowSteps->get($link->value)); - $this->set('vv_bc_parent_displayfield', $this->IdentifierCollectors->EnrollmentFlowSteps->getDisplayField()); - $this->set('vv_bc_parent_primarykey', $this->IdentifierCollectors->EnrollmentFlowSteps->getPrimaryKey()); - } - - return parent::beforeRender($event); - } /** * Dispatch an Enrollment Flow Step. diff --git a/app/plugins/CoreEnroller/src/Controller/InvitationAcceptersController.php b/app/plugins/CoreEnroller/src/Controller/InvitationAcceptersController.php index 172594124..17535e9c0 100644 --- a/app/plugins/CoreEnroller/src/Controller/InvitationAcceptersController.php +++ b/app/plugins/CoreEnroller/src/Controller/InvitationAcceptersController.php @@ -39,27 +39,6 @@ class InvitationAcceptersController extends StandardEnrollerController { 'InvitationAccepters.id' => 'asc' ] ]; - - /** - * Callback run prior to the request render. - * - * @param EventInterface $event Cake Event - * - * @return Response|void - * @since COmanage Registry v5.0.0 - */ - - public function beforeRender(\Cake\Event\EventInterface $event) { - $link = $this->getPrimaryLink(true); - - if(!empty($link->value)) { - $this->set('vv_bc_parent_obj', $this->InvitationAccepters->EnrollmentFlowSteps->get($link->value)); - $this->set('vv_bc_parent_displayfield', $this->InvitationAccepters->EnrollmentFlowSteps->getDisplayField()); - $this->set('vv_bc_parent_primarykey', $this->InvitationAccepters->EnrollmentFlowSteps->getPrimaryKey()); - } - - return parent::beforeRender($event); - } /** * Dispatch an Enrollment Flow Step. diff --git a/app/src/Controller/StandardEnrollerController.php b/app/src/Controller/StandardEnrollerController.php index ea70e6982..c7f6e2124 100644 --- a/app/src/Controller/StandardEnrollerController.php +++ b/app/src/Controller/StandardEnrollerController.php @@ -70,6 +70,17 @@ public function beforeRender(\Cake\Event\EventInterface $event) { $this->set('vv_petition', null); } + $link = $this->getPrimaryLink(true); + + if(!empty($link->value)) { + $currentTable = $this->getCurrentTable(); + $efsTable = $currentTable->getAssociation('EnrollmentFlowSteps')->getTarget(); + + $this->set('vv_bc_parent_obj', $efsTable->get($link->value)); + $this->set('vv_bc_parent_displayfield', $efsTable->getDisplayField()); + $this->set('vv_bc_parent_primarykey', $efsTable->getPrimaryKey()); + } + return parent::beforeRender($event); } From c7ef8925eacda57efcb066037ebc32bfe6f928f5 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Fri, 19 Sep 2025 08:25:56 +0300 Subject: [PATCH 2/3] Review comment changes --- app/src/Controller/Component/RegistryAuthComponent.php | 1 - app/src/Lib/Util/StringUtilities.php | 6 +++--- app/src/View/Helper/FieldHelper.php | 4 +--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/src/Controller/Component/RegistryAuthComponent.php b/app/src/Controller/Component/RegistryAuthComponent.php index d8c3f8d74..02afc8f52 100644 --- a/app/src/Controller/Component/RegistryAuthComponent.php +++ b/app/src/Controller/Component/RegistryAuthComponent.php @@ -49,7 +49,6 @@ namespace App\Controller\Component; -use App\Model\Entity; use \App\Lib\Enum\AuthenticationEventEnum; use \App\Lib\Enum\SuspendableStatusEnum; use \App\Lib\Enum\TemplateableStatusEnum; diff --git a/app/src/Lib/Util/StringUtilities.php b/app/src/Lib/Util/StringUtilities.php index feed2b562..1fde28fc4 100644 --- a/app/src/Lib/Util/StringUtilities.php +++ b/app/src/Lib/Util/StringUtilities.php @@ -146,7 +146,7 @@ public static function columnKey( // Otherwise look for the general key $cfield = __d('field', $c); - return ($cfield !== $c) ? $cfield : \Cake\Utility\Inflector::humanize($c); + return ($cfield !== $c) ? $cfield : Inflector::humanize($c); } /** @@ -188,7 +188,7 @@ public static function pluginToTextDomain(?string $plugin): string if (empty($plugin)) { return 'operation'; } - return \Cake\Utility\Inflector::singularize(\Cake\Utility\Inflector::tableize($plugin)); + return Inflector::underscore($plugin); } /** @@ -407,7 +407,7 @@ public static function localizeController(string $controllerName, ?string $plugi if ($pluginName) { // Localize via plugin - return __d(\Cake\Utility\Inflector::underscore($pluginName), 'controller.' . $controllerName, [$plural ? 99 : 1]); + return __d(Inflector::underscore($pluginName), 'controller.' . $controllerName, [$plural ? 99 : 1]); } // Standard Localization return __d('controller', $controllerName, [$plural ? 99 : 1]); diff --git a/app/src/View/Helper/FieldHelper.php b/app/src/View/Helper/FieldHelper.php index 57bda472c..60e3f9c31 100644 --- a/app/src/View/Helper/FieldHelper.php +++ b/app/src/View/Helper/FieldHelper.php @@ -104,9 +104,7 @@ public function calculateLabelAndDescription(string $fieldName): array $label = null; // First, try to autogenerate the field label (if we weren't given one). - $pluginDomain = (!empty($this->getPluginName()) - ? Inflector::underscore($this->getPluginName()) - : null); + $pluginDomain = StringUtilities::pluginToTextDomain($this->getPluginName()); $modelName = $this->getModelName(); // We try to automagically determine if a description for the field exists by From 30dd0e9e2607e72fb1fc949b856d9d4e56243b5d Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Sat, 20 Sep 2025 18:00:54 +0300 Subject: [PATCH 3/3] Improve pluginToTextDomain --- .../Component/BreadcrumbComponent.php | 3 +-- app/src/Lib/Util/StringUtilities.php | 6 +++--- app/src/Model/Table/JobsTable.php | 19 ++++++++++++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/src/Controller/Component/BreadcrumbComponent.php b/app/src/Controller/Component/BreadcrumbComponent.php index ccd86e65a..71bf699c5 100644 --- a/app/src/Controller/Component/BreadcrumbComponent.php +++ b/app/src/Controller/Component/BreadcrumbComponent.php @@ -274,8 +274,7 @@ public function injectPrimaryLink(object $link, bool $index = true, string $link [$title] = StringUtilities::entityAndActionToTitle( entity: $linkedEntity, modelPath: $linkModelFqn, - action: $breadcrumbAction, - domain: StringUtilities::pluginToTextDomain($link->plugin ?? null) + action: $breadcrumbAction ); $title = StringUtilities::stripActionPrefix($title); diff --git a/app/src/Lib/Util/StringUtilities.php b/app/src/Lib/Util/StringUtilities.php index 1fde28fc4..60b9f5227 100644 --- a/app/src/Lib/Util/StringUtilities.php +++ b/app/src/Lib/Util/StringUtilities.php @@ -180,13 +180,13 @@ public static function columnToAutoViewVar(string $column): string { * Determines the translation domain for a plugin * * @param string|null $plugin Plugin name - * @return string Translation domain + * @return string|null Translation domain * @since COmanage Registry v5.2.0 */ - public static function pluginToTextDomain(?string $plugin): string + public static function pluginToTextDomain(?string $plugin): ?string { if (empty($plugin)) { - return 'operation'; + return null; } return Inflector::underscore($plugin); } diff --git a/app/src/Model/Table/JobsTable.php b/app/src/Model/Table/JobsTable.php index 15f9012a8..3d016635c 100644 --- a/app/src/Model/Table/JobsTable.php +++ b/app/src/Model/Table/JobsTable.php @@ -30,7 +30,6 @@ namespace App\Model\Table; use Cake\Datasource\ConnectionManager; -use Cake\ORM\Query; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\ORM\TableRegistry; @@ -124,6 +123,24 @@ public function initialize(array $config): void { ] ]); } + + /** + * Table specific logic to generate a display field. + * + * @since COmanage Registry v5.2.0 + * @param Job $entity Entity to generate display field for + * @return string Display field + */ + + public function generateDisplayField(Job $entity): string { + // Try to find something renderable + + if(!empty($entity->plugin)) { + return $entity->plugin . " (" . $entity->id . ")"; + } + + return (string)$entity->id; + } /** * Assign a Job to a worker. This function should be called by the process