diff --git a/app/plugins/CoreEnroller/templates/AttributeCollectors/attribute.inc b/app/plugins/CoreEnroller/templates/AttributeCollectors/attribute.inc deleted file mode 100644 index d8dec4a3c..000000000 --- a/app/plugins/CoreEnroller/templates/AttributeCollectors/attribute.inc +++ /dev/null @@ -1,107 +0,0 @@ -default_value) => $attr->default_value, - isset($attr->default_value_env_name) - && getenv($attr->default_value_env_name) !== false => getenv($attr->default_value_env_name), - isset($attr->default_value_datetime) => $attr->default_value_datetime, - default => '' -}; - -// If we are re-rendering the Petition override the default value with whatever -// was previously saved -if(!empty($vv_petition_attributes)) { - $curEntity = $vv_petition_attributes->firstMatch(['enrollment_attribute_id' => $attr->id]); - - if(!empty($curEntity->value)) { - $options['default'] = $curEntity->value; - } -} - -// Construct the field arguments -$formArguments = [ - // We prefix the attribute ID with a string because Cake seems to sometimes have - // problems with field names that are purely integers (even if cast to strings) - 'fieldName' => 'field-' . $attr->id, - 'fieldLabel' => $attr->label, // fieldLabel is only applicable to checkboxes - 'fieldType' => $supportedAttributes['fieldType'], - 'fieldDescription' => $attr->description, - 'fieldNameAlias' => $attr->attribute // the field name to its enrollment attribute field name -]; - - -/* - * Get the values for the attributes ending with _id - * Supported for attributes: group_id, cou_id, affiliation_type_id - */ -if(str_ends_with($attr->attribute, '_id')) { - $suffix = substr($attr->attribute, 0, -3); - $suffix = Inflector::pluralize(Inflector::camelize($suffix)) ; - $defaultValuesPopulated = 'defaultValue' . $suffix; - if ($this->get($defaultValuesPopulated) !== null) { - $formArguments['fieldType'] = 'select'; - $formArguments['fieldSelectOptions'] = $this->get($defaultValuesPopulated); - } -} - -// READ-ONLY -if (isset($attr->modifiable) && !$attr->modifiable) { - $options['readonly'] = true; -} - -// REQUIRED -if (isset($attr->required) && $attr->required) { - $options['required'] = true; -} - -// Set the final fieldOptions -$formArguments['fieldOptions'] = $options; - -// HIDDEN Field -// We print directly, we do not delegate to the element for further processing -if ($attr->hidden) { - // In case this is a hidden field, we need to get only the value - print $this->Form->hidden($formArguments['fieldName'], ['value' => $options['default']]); -} else { - // Print the element - print $this->element('form/listItem', [ - 'arguments' => $formArguments - ]); -} \ No newline at end of file diff --git a/app/plugins/CoreEnroller/templates/element/mveas/fieldset-field.php b/app/plugins/CoreEnroller/templates/element/mveas/fieldset-field.php index 95820190d..754f861aa 100644 --- a/app/plugins/CoreEnroller/templates/element/mveas/fieldset-field.php +++ b/app/plugins/CoreEnroller/templates/element/mveas/fieldset-field.php @@ -40,8 +40,8 @@ if(isset($supportedAttributes['mveaModel'])) { $supportedAttributes = $this->Petition->getSupportedEnrollmentAttribute($attr->attribute); - $tableValidator = $this->Petition->getTableValidator($supportedAttributes['mveaModel']); - $isRequiredFromValidationRule = !$tableValidator->field($field)->isEmptyAllowed(); + $modelTable = $this->Petition->getTable($supportedAttributes['mveaModel']); + $isRequiredFromValidationRule = !$modelTable->getValidator()->field($field)->isEmptyAllowed(); } // Construct the field arguments @@ -50,7 +50,7 @@ // problems with field names that are purely integers (even if cast to strings) 'fieldName' => "field-$field-$attr->id", 'fieldLabel' => $attr->label, // fieldLabel is only applicable to checkboxes - 'fieldType' => $supportedAttributes['fieldType'], + 'fieldType' => $modelTable->getSchema()->getColumn($field)['type'], 'fieldNameAlias' => $attr->attribute // the field name to its enrollment attribute field name ]; ?> diff --git a/app/plugins/CoreEnroller/templates/element/mveas/fieldset-group.php b/app/plugins/CoreEnroller/templates/element/mveas/fieldset-group.php index fa7adc356..8ac21952a 100644 --- a/app/plugins/CoreEnroller/templates/element/mveas/fieldset-group.php +++ b/app/plugins/CoreEnroller/templates/element/mveas/fieldset-group.php @@ -44,32 +44,28 @@ if (!empty($cosettings[0][$permitted_fields_variable_name])) { $permitted_fields_list = explode(',', $cosettings[0][$permitted_fields_variable_name]); } -// Address has no permitted fields configuration at CO level. And according to our design, -// the permitted fields are found in CoSettings. -// For all the attributes that have no permitted configuration at the CO level, -// we will get all the fields that we support -// We will construct the list of permitted fields from the list of required fields. -// The permitted fields will be the set that contains all the required fields. -$requiredDropDownListVar = $attr->attribute . 'RequiredFields'; -if(empty($permitted_fields_list) && !empty($$requiredDropDownListVar)) { - usort($$requiredDropDownListVar, static fn($a, $b) => count(explode(',', $a)) <=> count(explode(',', $b))); - $permitted_fields = end($$requiredDropDownListVar); - $permitted_fields_list = collection(explode(',', $permitted_fields))->map(fn($value) => trim($value)); +// Address has no permitted fields configuration at CO level. We will get them from +// the model configuration +$supportedAttributes = $this->Petition->getSupportedEnrollmentAttribute($attr->attribute); +$modelTable = $this->Petition->getTable($supportedAttributes['mveaModel']); +if(empty($permitted_fields_list) && !empty($modelTable?->getPermittedFields())) { + $permitted_fields_list = $modelTable->getPermittedFields(); } +$permitted_fields_list_flipped = array_flip($permitted_fields_list); + ?> $fields): ?>
map(static fn($value) => str_replace(' ', '_', Inflector::underscore($value))); foreach($fields as $field) { - if($permitted_fields_list->contains($field)) { + if(isset($permitted_fields_list_flipped[$field])) { // Print the element print $this->element('CoreEnroller.mveas/fieldset-field', compact('field', 'attr')); } - // Remove the field we render from the permitted list. - $permitted_fields_list = $permitted_fields_list->filter(fn($value) => $value !== $field); + // Remove the field we rendered from the permitted list. + unset($permitted_fields_list_flipped[$field]); } ?>
@@ -78,7 +74,7 @@ element('CoreEnroller.mveas/fieldset-field', compact('field', 'attr')); } ?> diff --git a/app/src/Model/Table/AddressesTable.php b/app/src/Model/Table/AddressesTable.php index fa0f81f16..3a0d80187 100644 --- a/app/src/Model/Table/AddressesTable.php +++ b/app/src/Model/Table/AddressesTable.php @@ -59,6 +59,9 @@ class AddressesTable extends Table { 'postal' ] ]; + + // Default permitted Fields. Used for the Attribute Collection + private $permittedFields = ['locality', 'state', 'postal_code', 'country', 'street', 'room']; /** * Perform Cake Model initialization. @@ -262,4 +265,14 @@ public function validationDefault(Validator $validator): Validator { return $validator; } + + /** + * Get the hardcoded list of the Default Permitted Fields + * + * @since COmanage Registry v5.0.0 + * @return array List of permitted fields + */ + public function getPermittedFields(): array { + return $this->permittedFields; + } } \ No newline at end of file diff --git a/app/src/View/Helper/FieldHelper.php b/app/src/View/Helper/FieldHelper.php index 03749912d..3f4b5cf13 100644 --- a/app/src/View/Helper/FieldHelper.php +++ b/app/src/View/Helper/FieldHelper.php @@ -409,6 +409,7 @@ public function formField(string $fieldName, 'class' => 'form-check-input', ]), 'select' => $this->Form->select($fieldName, $fieldSelectOptions, $fieldArgs), + 'text' => $this->Form->textarea($fieldName, $fieldArgs), 'date' => $this->dateField(fieldName: $fieldName, dateType: DateTypeEnum::DateOnly, fieldArgs: $fieldArgs), 'datetime', 'timestamp' => $this->dateField(fieldName: $fieldName, fieldArgs: $fieldArgs), diff --git a/app/src/View/Helper/PetitionHelper.php b/app/src/View/Helper/PetitionHelper.php index 91234d80a..2de9a6364 100644 --- a/app/src/View/Helper/PetitionHelper.php +++ b/app/src/View/Helper/PetitionHelper.php @@ -88,12 +88,11 @@ public function populateAutoViewVars(): void * * @param string $tableName * - * @return Validator + * @return Table * @since COmanage Registry v5.0.0 */ - public function getTableValidator(string $tableName): \Cake\Validation\Validator + public function getTable(string $tableName): Table { - $ModelTable = TableRegistry::getTableLocator()->get($tableName); - return $ModelTable->getValidator();// For MVEAs we retrieve the validation rules from CoSettings. Telephone numbers are different + return TableRegistry::getTableLocator()->get($tableName); } } \ No newline at end of file