From 2fdaca540bfe3504e66b27de0f92c6c1bd89f43a Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Sun, 1 Nov 2026 06:31:01 +0000 Subject: [PATCH 1/5] CO-2981/CFM-324 Extract dispatch form parsing in AttributeCollectorsTable::upsert() into parseFormAttributes() --- .../Model/Table/AttributeCollectorsTable.php | 101 +++++++++++------- 1 file changed, 63 insertions(+), 38 deletions(-) diff --git a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php index f29a7f081..185b9bb05 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php @@ -611,6 +611,45 @@ protected function enforceCouAttributes(int $id, int $petitionId, array $attribu return $attributes; } + /** + * Parse the submitted dispatch form fields into Enrollment Attribute values. + * Form keys are either field- (single valued attributes) or + * field-- (multi valued attributes, eg Names or Addresses). + * + * @since COmanage Registry v5.4.0 + * @param array $attributes Submitted form fields + * @return array Values, keyed on Enrollment Attribute ID and then column name ('' for single valued attributes) + */ + + protected function parseFormAttributes(array $attributes): array { + $parsed = []; + + foreach($attributes as $enrollmentAttributeLabel => $value) { + // Remove field- prefix from the form field name + $fieldToParts = explode('-', (string)$enrollmentAttributeLabel); + // MVAs have multiple columns. For example a name has: + // given, surname, prefix, ... + $columnName = ''; + if (count($fieldToParts) > 2) { + // There is a type ID in the middle + $columnName = $fieldToParts[1]; + } + // The enrollment Attribute ID is the last part + $enrollmentAttributeId = (int)array_pop($fieldToParts); + + // The people picker will send a complex string and not just the id. We need to extract it ourselves. + $re = '/^.*\(ID: (\d+)\)$/m'; + preg_match_all($re, (string)$value, $matches, PREG_SET_ORDER, 0); + if(!empty($matches)) { + $value = $matches[0][1]; + } + + $parsed[$enrollmentAttributeId][$columnName] = $value; + } + + return $parsed; + } + /** * Insert or update a set of Petition Attributes. * @@ -642,52 +681,38 @@ public function upsert(int $id, int $petitionId, array $attributes) { $petitionAttributes = []; - foreach($attributes as $enrollmentAttributeLabel => $value) { - // Remove field- prefix from the form field name - $fieldToParts = explode('-', $enrollmentAttributeLabel); - // MVAs have multiple columns. For example a name has: - // given, surname, prefix, ... - $columnName = null; - if (count($fieldToParts) > 2) { - // There is a type ID in the middle - $columnName = $fieldToParts[1]; - } - // The enrollment Attribute ID is the last part - $enrollmentAttributeId = (int)array_pop($fieldToParts); - - // The people picker will send a complex string and not just the id. We need to extract it ourselves. - $re = '/^.*\(ID: (\d+)\)$/m'; - preg_match_all($re, $value, $matches, PREG_SET_ORDER, 0); - if(!empty($matches)) { - $value = $matches[0][1]; - } + foreach($this->parseFormAttributes($attributes) as $enrollmentAttributeId => $columns) { + foreach($columns as $column => $value) { + // An empty column key means a single valued attribute + $columnName = ($column === '') ? null : (string)$column; - $newAttribute = [ - 'petition_id' => $petitionId, - 'enrollment_attribute_id' => $enrollmentAttributeId, - 'value' => $value, - // This is the column name for the attributes that consist of multiple fields, like the name or the address - 'column_name' => $columnName, - ]; + $newAttribute = [ + 'petition_id' => $petitionId, + 'enrollment_attribute_id' => $enrollmentAttributeId, + 'value' => $value, + // This is the column name for the attributes that consist of multiple fields, like the name or the address + 'column_name' => $columnName, + ]; - if(\array_key_exists($enrollmentAttributeId, $currentAttributes)) { - // This is an update of an existing attribute + if(\array_key_exists($enrollmentAttributeId, $currentAttributes)) { + // This is an update of an existing attribute - $newAttribute['id'] = $currentAttributes[$enrollmentAttributeId]; + $newAttribute['id'] = $currentAttributes[$enrollmentAttributeId]; - $entity = $this->EnrollmentAttributes - ->PetitionAttributes->get($newAttribute['id']); + $entity = $this->EnrollmentAttributes + ->PetitionAttributes->get($newAttribute['id']); - // We don't bother with patch entity since the only thing we support - // changing is value + // We don't bother with patch entity since the only thing we support + // changing is value - $entity->value = $value; + $entity->value = $value; - $this->EnrollmentAttributes->PetitionAttributes->saveOrFail($entity); + $this->EnrollmentAttributes->PetitionAttributes->saveOrFail($entity); // XXX we could record petition history that this specific attribute was updated - } else { - // This is a new attribute - $petitionAttributes[] = $newAttribute; + } else { + // This is a new attribute + $petitionAttributes[] = $newAttribute; + } } } From ea4bf9a4af96eea8addefc8b3ca74e39df731733 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Sun, 1 Nov 2026 06:58:17 +0000 Subject: [PATCH 2/5] CO-2981/CFM-324 Validate Attribute Collector values against target models at dispatch, throwing new core App\Lib\Exception\ValidationException --- .../Model/Table/AttributeCollectorsTable.php | 211 ++++++++++++++++++ app/src/Lib/Exception/ValidationException.php | 101 +++++++++ 2 files changed, 312 insertions(+) create mode 100644 app/src/Lib/Exception/ValidationException.php diff --git a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php index 185b9bb05..a9ffd7810 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php @@ -31,6 +31,7 @@ use App\Lib\Enum\PetitionActionEnum; use App\Lib\Enum\StatusEnum; +use App\Lib\Exception\ValidationException; use App\Model\Entity\Person; use App\Model\Entity\PersonRole; use Cake\Collection\Collection; @@ -42,6 +43,7 @@ use Cake\ORM\Table; use Cake\ORM\TableRegistry; use Cake\Utility\Hash; +use Cake\Utility\Inflector; use Cake\Validation\Validator; class AttributeCollectorsTable extends Table { @@ -667,6 +669,9 @@ public function upsert(int $id, int $petitionId, array $attributes) { // Enforce the COU server side, before anything is stored $attributes = $this->enforceCouAttributes($id, $petitionId, $attributes); + // Validate the submitted values against the target models, before anything is stored + $this->validateAttributes($id, $petitionId, $attributes); + // Do we have existing attributes for this petition? Note this will pull // _all_ attributes for the Petition, not just those associated with this // particular Attribute Collector; however we'll only look at the attributes @@ -738,6 +743,212 @@ public function upsert(int $id, int $petitionId, array $attributes) { return true; } + /** + * Validate the submitted dispatch form fields against the validation rules of the + * models they will be saved to at finalization (eg Telephone Numbers or Person Roles), + * so that invalid values can be corrected before the step completes. + * + * @since COmanage Registry v5.4.0 + * @param int $id Attribute Collector ID + * @param int $petitionId Petition ID + * @param array $attributes Submitted form fields + * @throws ValidationException + */ + + public function validateAttributes(int $id, int $petitionId, array $attributes): void { + $parsed = $this->parseFormAttributes($attributes); + + if(empty($parsed)) { + return; + } + + $enrollmentAttributes = $this->EnrollmentAttributes + ->find() + ->where([ + 'attribute_collector_id' => $id, + 'status' => StatusEnum::Active + ]) + ->where(fn(QueryExpression $exp, Query $q) => $exp->in('id', array_keys($parsed))) + ->orderBy(['ordr' => 'ASC']) + ->toArray(); + + if(empty($enrollmentAttributes)) { + return; + } + + $supportedAttributes = $this->EnrollmentAttributes->supportedAttributes(); + $coId = (int)TableRegistry::getTableLocator()->get('Petitions')->findCoForRecord($petitionId); + $now = FrozenTime::now(); + + // Single valued MVEAs are stored in this column of the MVEA model + $valueColumns = [ + 'adHocAttribute' => 'value', + 'emailAddress' => 'mail', + 'identifier' => 'identifier', + 'pronoun' => 'pronouns', + 'url' => 'url' + ]; + + // Single valued Person and Person Role attributes are combined into one record each, + // the same way hydrate() saves them + $combined = [ + 'Person' => ['table' => 'People', 'data' => [], 'labels' => []], + 'PersonRole' => ['table' => 'PersonRoles', 'data' => [], 'labels' => []] + ]; + + $errors = []; + + foreach($enrollmentAttributes as $ea) { + $attr = $supportedAttributes[$ea->attribute] ?? null; + + if(empty($attr)) { + continue; + } + + $label = !empty($ea->label) ? $ea->label : $attr['label']; + $values = $parsed[(int)$ea->id]; + + if(!empty($attr['mveaModel'])) { + $data = []; + + foreach($values as $column => $value) { + if($column === '') { + if(!isset($valueColumns[$ea->attribute])) { + continue; + } + $column = $valueColumns[$ea->attribute]; + } + $data[(string)$column] = $value; + } + + $isEmpty = empty(array_filter($data, fn($v) => $v !== null && trim((string)$v) !== '')); + + // Optional MVEAs left empty are skipped, as they are not saved at finalization + if(empty($data) || ($isEmpty && !$ea->required)) { + continue; + } + + if($ea->attribute === 'adHocAttribute') { + if(!$ea->required && ($ea->attribute_tag === null || trim((string)$ea->attribute_tag) === '')) { + continue; + } + $data['tag'] = $ea->attribute_tag; + } else { + $data['type_id'] = $ea->attribute_type; + } + + if(in_array($ea->attribute, ['name', 'pronoun'], true) && !empty($ea->attribute_language)) { + $data['language'] = $ea->attribute_language; + } + + $this->collectValidationErrors($attr['mveaModel'], $coId, $data, $label, $errors); + } elseif(($attr['model'] ?? null) === 'Group') { + // Each Group Membership is saved as its own record + $value = $values[''] ?? reset($values); + + if($value === null || $value === '') { + continue; + } + + $this->collectValidationErrors('GroupMembers', $coId, [$ea->attribute => $value], $label, $errors); + } elseif(isset($combined[$attr['model'] ?? ''])) { + $value = $values[''] ?? reset($values); + + if($ea->attribute === 'valid_from' || $ea->attribute === 'valid_through') { + try { + $value = $this->EnrollmentAttributes->resolveValidityDate($ea->attribute, $value, $ea, $now); + } catch(\Exception $e) { + $errors[$this->validationErrorLabel($label, $ea->attribute)] = [ + 'content' => __d('error', 'invalid', [(string)$value]) + ]; + continue; + } + } + + $combined[$attr['model']]['data'][$ea->attribute] = $value; + $combined[$attr['model']]['labels'][$ea->attribute] = $label; + } + // Petition attributes are only stored in the Petition, so there is nothing to validate + } + + foreach($combined as $c) { + if(!empty($c['data'])) { + $this->collectValidationErrors($c['table'], $coId, $c['data'], $c['labels'], $errors); + } + } + + if(!empty($errors)) { + throw new ValidationException($errors); + } + } + + /** + * Validate a record against the default validator of a target model, and collect + * the errors on the validated fields. + * + * @since COmanage Registry v5.4.0 + * @param string $tableName Target table name (eg TelephoneNumbers) + * @param int $coId CO ID, used for CO Settings dependent validation rules + * @param array $data Record to validate + * @param string|array $label Attribute label, or array of field => Attribute label + * @param array $errors Collected errors, keyed on " ()" + */ + + protected function collectValidationErrors( + string $tableName, + int $coId, + array $data, + string|array $label, + array &$errors + ): void { + $table = TableRegistry::getTableLocator()->get($tableName); + + // Some validators (eg Telephone Numbers) depend on CO Settings, so the CO must + // be known before the validator is built + if(!empty($coId) && method_exists($table, 'setCurCoId')) { + $table->setCurCoId($coId); + } + + // Foreign keys to the Person, Person Role or Group are only known at finalization + $ignore = ['person_id', 'person_role_id', 'group_id']; + if(method_exists($table, 'getPrimaryLinks')) { + $ignore = array_merge($ignore, $table->getPrimaryLinks()); + } + // ... unless the key is the collected value itself (eg the Group of a Group Membership) + $ignore = array_diff($ignore, array_keys($data)); + + $result = $table->getValidator()->validate($data, true); + + foreach($result as $field => $fieldErrors) { + if(in_array($field, $ignore, true) || !array_key_exists($field, $data)) { + continue; + } + + $attrLabel = is_array($label) ? ($label[$field] ?? $field) : $label; + + $errors[$this->validationErrorLabel($attrLabel, (string)$field)] = $fieldErrors; + } + } + + /** + * Construct the label used to report a validation error. + * + * @since COmanage Registry v5.4.0 + * @param string $attrLabel Enrollment Attribute label + * @param string $field Field name + * @return string Label, as " ()" + */ + + protected function validationErrorLabel(string $attrLabel, string $field): string { + $fieldLabel = __d('field', $field); + + if($fieldLabel === $field) { + $fieldLabel = Inflector::humanize($field); + } + + return $attrLabel . ' (' . $fieldLabel . ')'; + } + /** * Set validation rules. * diff --git a/app/src/Lib/Exception/ValidationException.php b/app/src/Lib/Exception/ValidationException.php new file mode 100644 index 000000000..d33833e6c --- /dev/null +++ b/app/src/Lib/Exception/ValidationException.php @@ -0,0 +1,101 @@ + message + protected array $errors = []; + + /** + * Constructor. + * + * @since COmanage Registry v5.4.0 + * @param array $errors Validation errors, keyed on field (or label), each an array of rule => message + */ + + public function __construct(array $errors) { + $this->errors = $errors; + + parent::__construct(implode('; ', $this->getMessages())); + } + + /** + * Construct a Validation Exception from the errors of an entity, eg after a failed save. + * + * @since COmanage Registry v5.4.0 + * @param EntityInterface $entity Entity with errors + * @return static Validation Exception + */ + + public static function fromEntity(EntityInterface $entity): static { + return new static($entity->getErrors()); + } + + /** + * Obtain the validation errors. + * + * @since COmanage Registry v5.4.0 + * @return array Validation errors, keyed on field (or label), each an array of rule => message + */ + + public function getErrors(): array { + return $this->errors; + } + + /** + * Obtain the validation errors as a list of human readable messages. + * + * @since COmanage Registry v5.4.0 + * @return array Messages, each formatted as ": " + */ + + public function getMessages(): array { + $messages = []; + + foreach($this->errors as $label => $fieldErrors) { + foreach((array)$fieldErrors as $msg) { + // Nested entity errors (eg associated records) are flattened + if(is_array($msg)) { + $msg = implode(', ', array_filter(array_map( + fn($m) => is_scalar($m) ? (string)$m : null, + Hash::flatten($msg) + ))); + } + + $messages[] = $label . ': ' . $msg; + } + } + + return $messages; + } +} From 3c7b99ef2494f4626e80efba523ef95ca7dc85f9 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Mon, 2 Nov 2026 15:53:17 +0000 Subject: [PATCH 3/5] CO-2981/CFM-324 Show Attribute Collector validation errors on dispatch, fix resubmit updating MVEA columns, tolerate null field descriptions --- .../resources/locales/en_US/core_enroller.po | 3 +++ .../AttributeCollectorsController.php | 10 +++++++ .../Model/Table/AttributeCollectorsTable.php | 26 ++++++++++++------- .../templates/element/fieldDiv.php | 2 +- app/templates/element/form/fieldDiv.php | 2 +- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po b/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po index 2462db1cb..a60173e81 100644 --- a/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po +++ b/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po @@ -109,6 +109,9 @@ msgstr "DefaultVerificationValidity" msgid "error.ApprovalCollectors.comment" msgstr "Comment is required" +msgid "error.attr.invalid" +msgstr "Please correct the following: {0}" + msgid "error.CouSelectors.cou_id.invalid" msgstr "Requested COU {0} is not a valid option" diff --git a/app/plugins/CoreEnroller/src/Controller/AttributeCollectorsController.php b/app/plugins/CoreEnroller/src/Controller/AttributeCollectorsController.php index e06d3eb05..ab1bf70bd 100644 --- a/app/plugins/CoreEnroller/src/Controller/AttributeCollectorsController.php +++ b/app/plugins/CoreEnroller/src/Controller/AttributeCollectorsController.php @@ -30,6 +30,7 @@ namespace CoreEnroller\Controller; use App\Controller\StandardEnrollerController; +use App\Lib\Exception\ValidationException; use Cake\Event\EventInterface; use Cake\Http\Response; use Cake\ORM\TableRegistry; @@ -76,6 +77,15 @@ public function dispatch(string $id) { comment: __d('core_enroller', 'result.attr.saved') ); } + catch(ValidationException $e) { + // List each invalid field, so the Enrollee can correct the values and resubmit + $items = array_map(fn($m) => '
  • ' . h($m) . '
  • ', $e->getMessages()); + + $this->Flash->error( + __d('core_enroller', 'error.attr.invalid', ['
      ' . implode('', $items) . '
    ']), + ['escape' => false] + ); + } catch(\Exception $e) { $this->Flash->error($e->getMessage()); } diff --git a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php index a9ffd7810..cb6390ae0 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php @@ -675,14 +675,20 @@ public function upsert(int $id, int $petitionId, array $attributes) { // Do we have existing attributes for this petition? Note this will pull // _all_ attributes for the Petition, not just those associated with this // particular Attribute Collector; however we'll only look at the attributes - // we need below. - $currentAttributes = $this->EnrollmentAttributes - ->PetitionAttributes->find('list', - keyField: 'enrollment_attribute_id', - valueField: 'id', - ) - ->where(['petition_id' => $petitionId]) - ->toArray(); + // we need below. Multi valued attributes (eg Names or Telephone Numbers) have + // one Petition Attribute per column, so these are keyed on Enrollment Attribute + // ID and then column name ('' for single valued attributes). + $currentAttributes = []; + + $existing = $this->EnrollmentAttributes + ->PetitionAttributes->find() + ->select(['id', 'enrollment_attribute_id', 'column_name']) + ->where(['petition_id' => $petitionId]) + ->all(); + + foreach($existing as $pa) { + $currentAttributes[(int)$pa->enrollment_attribute_id][(string)($pa->column_name ?? '')] = (int)$pa->id; + } $petitionAttributes = []; @@ -699,10 +705,10 @@ public function upsert(int $id, int $petitionId, array $attributes) { 'column_name' => $columnName, ]; - if(\array_key_exists($enrollmentAttributeId, $currentAttributes)) { + if(isset($currentAttributes[$enrollmentAttributeId][(string)$column])) { // This is an update of an existing attribute - $newAttribute['id'] = $currentAttributes[$enrollmentAttributeId]; + $newAttribute['id'] = $currentAttributes[$enrollmentAttributeId][(string)$column]; $entity = $this->EnrollmentAttributes ->PetitionAttributes->get($newAttribute['id']); diff --git a/app/plugins/CoreEnroller/templates/element/fieldDiv.php b/app/plugins/CoreEnroller/templates/element/fieldDiv.php index 0f1c84764..bc81dcdf0 100644 --- a/app/plugins/CoreEnroller/templates/element/fieldDiv.php +++ b/app/plugins/CoreEnroller/templates/element/fieldDiv.php @@ -35,7 +35,7 @@ print $this->element('form/nameDiv'); // This configuration isn't necessary anymore. - if(isset($vv_field_arguments['fieldDescription'])) { + if(array_key_exists('fieldDescription', $vv_field_arguments)) { unset($vv_field_arguments['fieldDescription']); $this->set('vv_field_arguments', $vv_field_arguments); } diff --git a/app/templates/element/form/fieldDiv.php b/app/templates/element/form/fieldDiv.php index 53ca80019..3ce9187fd 100644 --- a/app/templates/element/form/fieldDiv.php +++ b/app/templates/element/form/fieldDiv.php @@ -35,7 +35,7 @@ print $this->element('form/nameDiv'); // This configuration isn't necessary anymore. - if(isset($vv_field_arguments['fieldDescription'])) { + if(array_key_exists('fieldDescription', $vv_field_arguments)) { unset($vv_field_arguments['fieldDescription']); $this->set('vv_field_arguments', $vv_field_arguments); } From e3bb7b0935f6e9b7e93c20e1c132b05ec11f33c5 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Mon, 9 Nov 2026 09:24:27 +0000 Subject: [PATCH 4/5] CO-3034 Respect optional Enrollment Attribute for MVEA sub-fields and skip empty optional MVEAs at finalization --- .../src/Model/Table/AttributeCollectorsTable.php | 10 ++++++++++ .../templates/element/mveas/fieldset-field.php | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php index cb6390ae0..657a37261 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/AttributeCollectorsTable.php @@ -510,6 +510,16 @@ protected function handleMveaAttributes( return $attr['enrollment_attribute_id'] == $attribute_id; })->toArray(); + // Do not create a model record for a completely empty optional MVEA. + $firstField = reset($fieldsForAttribute); + $hasValue = !empty(array_filter($fieldsForAttribute, function($field) { + return $field['value'] !== null + && (!is_string($field['value']) || trim($field['value']) !== ''); + })); + if(empty($firstField['enrollment_attribute']['required']) && !$hasValue) { + continue; + } + $supportedAttributes = $this->EnrollmentAttributes->supportedAttributes(); $mveaModel = $supportedAttributes[$attribute]['mveaModel']; diff --git a/app/plugins/CoreEnroller/templates/element/mveas/fieldset-field.php b/app/plugins/CoreEnroller/templates/element/mveas/fieldset-field.php index c13565812..7c82c83d2 100644 --- a/app/plugins/CoreEnroller/templates/element/mveas/fieldset-field.php +++ b/app/plugins/CoreEnroller/templates/element/mveas/fieldset-field.php @@ -49,7 +49,8 @@ } // Is the field required? -$options['required'] = $isRequiredFromValidationRule; +$isRequiredForEnrollment = !empty($attr->required) && $isRequiredFromValidationRule; +$options['required'] = $isRequiredForEnrollment; // Do we have a default value configured? // Either a value or an Environmental Variable, @@ -117,7 +118,7 @@
    "> - element('form/requiredSpan') : ''?> + element('form/requiredSpan') : ''?> Field->formField(...$formArguments) ?>
    From 61e67b7c1ad8238ffdf81328c7421222aca5dc0b Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Mon, 9 Nov 2026 09:31:54 +0000 Subject: [PATCH 5/5] CO-3034 Show hint under optional MVEA title explaining that required sub-fields (e.g. Given) apply once any part is filled in --- .../resources/locales/en_US/core_enroller.po | 3 + .../templates/element/mveas/fieldset-desc.php | 71 +++++++++++++++++++ .../templates/element/mveas/mvea-fieldset.php | 1 + 3 files changed, 75 insertions(+) create mode 100644 app/plugins/CoreEnroller/templates/element/mveas/fieldset-desc.php diff --git a/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po b/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po index a60173e81..d2bd0cd4e 100644 --- a/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po +++ b/app/plugins/CoreEnroller/resources/locales/en_US/core_enroller.po @@ -163,6 +163,9 @@ msgstr "This Invitation has already been processed" msgid "information.ApprovalCollectors.review" msgstr "Please approve or deny Petition {0}." +msgid "information.AttributeCollectors.mvea_optional" +msgstr "You may leave this {0} blank. If you provide any part of it, also provide all required fields: {1}." + msgid "information.EmailVerifiers.done" msgstr "All email addresses in this Petition have been verified. You may continue on to the next Enrollment Step." diff --git a/app/plugins/CoreEnroller/templates/element/mveas/fieldset-desc.php b/app/plugins/CoreEnroller/templates/element/mveas/fieldset-desc.php new file mode 100644 index 000000000..fefe85a9d --- /dev/null +++ b/app/plugins/CoreEnroller/templates/element/mveas/fieldset-desc.php @@ -0,0 +1,71 @@ +required)) { + return; +} + +$permitted_fields_list = []; +$permitted_fields_variable_name = 'permitted_fields_' . Inflector::underscore($attr->attribute); +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. 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(); +} + +$required_fields_list = []; +$validator = $modelTable->getValidator(); +foreach($permitted_fields_list as $field) { + if(!$validator->field($field)->isEmptyAllowed()) { + $required_fields_list[] = Inflector::humanize($field); + } +} + +if(empty($required_fields_list)) { + return; +} +?> + +
    + label, implode(', ', $required_fields_list)] + )) ?> +
    diff --git a/app/plugins/CoreEnroller/templates/element/mveas/mvea-fieldset.php b/app/plugins/CoreEnroller/templates/element/mveas/mvea-fieldset.php index 9bda744ab..de542af93 100644 --- a/app/plugins/CoreEnroller/templates/element/mveas/mvea-fieldset.php +++ b/app/plugins/CoreEnroller/templates/element/mveas/mvea-fieldset.php @@ -51,6 +51,7 @@ + element('CoreEnroller.mveas/fieldset-desc', compact('attr')) ?>
    element('CoreEnroller.mveas/fieldset-group', compact( 'attr')) ?>