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): ?>