Skip to content

Commit

Permalink
Make field types available to views/FieldHelper (CFM-219)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Oct 6, 2022
1 parent 878edac commit f67487d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/src/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit f67487d

Please sign in to comment.