From ebb11a80df4f4683f3336af612fbe68c13173728 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Thu, 24 Oct 2024 16:09:25 +0300 Subject: [PATCH] Fix Attribute Collectors dispatch view dependency data --- .../Controller/StandardEnrollerController.php | 8 ++++- app/src/View/Helper/PetitionHelper.php | 29 +++++++++++++------ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/app/src/Controller/StandardEnrollerController.php b/app/src/Controller/StandardEnrollerController.php index 4972655ae..601141bbf 100644 --- a/app/src/Controller/StandardEnrollerController.php +++ b/app/src/Controller/StandardEnrollerController.php @@ -51,8 +51,14 @@ class StandardEnrollerController extends StandardPluginController { */ public function beforeRender(\Cake\Event\EventInterface $event) { + $Petition = TableRegistry::getTableLocator()->get('Petitions'); // Make the Petition available to the view - $this->set('vv_petition', $this->petition); + $this->set( + 'vv_petition', + $Petition->findById($this->petition->id) + ->contain($Petition->getIndexContains()) + ->firstOrFail() + ); return parent::beforeRender($event); } diff --git a/app/src/View/Helper/PetitionHelper.php b/app/src/View/Helper/PetitionHelper.php index 3b4253b85..eea417c3a 100644 --- a/app/src/View/Helper/PetitionHelper.php +++ b/app/src/View/Helper/PetitionHelper.php @@ -44,29 +44,40 @@ class PetitionHelper extends Helper // The current entity, if edit or view protected ?object $entity = null; + protected ?object $petition = null; + public function initialize(array $config): void { parent::initialize($config); $this->entity = $this->getView()->get('vv_obj'); + $this->petition = $this->getView()->get('vv_petition'); $this->enrollmentAttributesTable = new EnrollmentAttributesTable(); } - /** - * Get the - * - * @param string $attribute - * - * @return array - * @since COmanage Registry v5.0.0 - */ + /** + * Get the Enrollment Attribute hardcoded configuration + * + * @param string $attribute + * + * @return array + * @since COmanage Registry v5.0.0 + */ public function getSupportedEnrollmentAttribute(string $attribute): array { return $this->enrollmentAttributesTable->supportedAttributes()[$attribute]; } + /** + * Calculate and populate the Enrollment Attributes auto view vars + * + * @since COmanage Registry v5.0.0 + */ public function populateAutoViewVars(): void { - foreach ($this->enrollmentAttributesTable->calculateAutoViewVars(2, $this->entity) as $vvar => $value) { + // XXX Find the co id + foreach ( + $this->enrollmentAttributesTable->calculateAutoViewVars($this->petition?->enrollment_flow?->co_id,$this->entity) as $vvar => $value + ) { $this->getView()->set($vvar, $value); } }