From f67487de7bb7ea0b57c34f3134267d718a9b9511 Mon Sep 17 00:00:00 2001 From: Benn Oshrin Date: Thu, 6 Oct 2022 10:02:04 -0400 Subject: [PATCH] Make field types available to views/FieldHelper (CFM-219) --- app/src/Controller/StandardController.php | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/src/Controller/StandardController.php b/app/src/Controller/StandardController.php index 184beea8c..4bf4fea62 100644 --- a/app/src/Controller/StandardController.php +++ b/app/src/Controller/StandardController.php @@ -117,6 +117,8 @@ public function beforeRender(\Cake\Event\EventInterface $event) { // $table = the actual table object $table = $this->$modelsName; + // Provide some hints to the views + $this->getFieldTypes(); $this->getRequiredFields(); // Set the display field as a view var to make it available to the views @@ -376,6 +378,29 @@ public function generateRedirect(?int $id) { return $this->redirect($redirect); } + /** + * Make a list of fields types suitable for FieldHelper + * + * @since COmanage Registry v5.0.0 + */ + + protected function getFieldTypes() { + // $this->name = Models (ie: from ModelsTable) + $modelsName = $this->name; + // $table = the actual table object + $table = $this->$modelsName; + + $schema = $table->getSchema(); + + // We don't pass the schema object as is, partly because cake might change it + // and partly to simplify access to the parts the views (FieldHelper, really) + // actually need. + + // Note the schema does have field lengths for strings, but typeMap + // doesn't return them and we're not doing anything with them at the moment. + $this->set('vv_field_types', $schema->typeMap()); + } + /** * Build a list of required fields suitable for FieldHelper *