Skip to content

Commit

Permalink
use common mva delimiters along with free text input
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Apr 15, 2026
1 parent 9ffc7ca commit 74f7eee
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/plugins/EnvSource/config/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"id": {},
"external_identity_source_id": {},
"redirect_on_duplicate": { "type": "url" },
"sp_mode": { "type": "enum" },
"mva_delimiter": { "type": "string", "size": "5" },
"sync_on_login": { "type": "boolean"},
"default_affiliation_type_id": { "type": "integer", "foreignkey": { "table": "types", "column": "id" } },
"address_type_id": { "type": "integer", "foreignkey": { "table": "types", "column": "id" } },
Expand Down
7 changes: 5 additions & 2 deletions app/plugins/EnvSource/resources/locales/en_US/env_source.po
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ msgstr "Source Key {0} is already attached to External Identity {1}"
msgid "field.EnvSources.address_type_id"
msgstr "Address Type"

msgid "field.EnvSources.mva_delimiter_common"
msgstr "Common Delimiters"

msgid "field.EnvSources.default_affiliation_type_id"
msgstr "Default Affiliation Type"

Expand Down Expand Up @@ -145,8 +148,8 @@ msgstr "Path to lookaside file, intended for testing only"
msgid "field.EnvSources.redirect_on_duplicate"
msgstr "Redirect on Duplicate"

msgid "field.EnvSources.sp_mode"
msgstr "Web Server Service Provider"
msgid "field.EnvSources.mva_delimiter"
msgstr "Service Provider Multi Value Delimiter"

msgid "field.EnvSources.sync_on_login"
msgstr "Sync on Login"
Expand Down
27 changes: 9 additions & 18 deletions app/plugins/EnvSource/src/Model/Table/EnvSourcesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,21 +280,15 @@ protected function resultToEntityData(

// Email Address
if(!empty($result['env_mail'])) {
$mails = [];

// We accept multiple values if supported by the configured SP software.

switch($EnvSource->sp_mode) {
case EnvSourceSpModeEnum::Shibboleth:
$mails = explode(";", $result['env_mail']);
break;
case EnvSourceSpModeEnum::SimpleSamlPhp:
$mails = explode(",", $result['env_mail']);
break;
default:
// We dont' try to tokenize the string
$mails = [ $result['env_mail' ]];
break;
$delimiter = $EnvSource->mva_delimiter;
$stringValue = $result['env_mail'];

// Check if the delimiter is provided and not an empty string
if (!empty($delimiter)) {
$mails = explode($delimiter, $stringValue);
} else {
$mails = [$stringValue];
}

foreach($mails as $m) {
Expand Down Expand Up @@ -443,10 +437,7 @@ public function validationDefault(Validator $validator): Validator {
]);
$validator->allowEmptyString('redirect_on_duplicate');

$validator->add('sp_mode', [
'content' => ['rule' => ['inList', EnvSourceSpModeEnum::getConstValues()]]
]);
$validator->notEmptyString('sp_mode');
$this->registerStringValidation($validator, $schema, 'mva_delimiter', true);

$validator->add('sync_on_login', [
'content' => ['rule' => 'boolean']
Expand Down
91 changes: 90 additions & 1 deletion app/plugins/EnvSource/templates/EnvSources/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,98 @@
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

use EnvSource\Lib\Enum\EnvSourceSpModeEnum;

// Build the delimiter map dynamically from your $spModes array
$phpDelimiterMap = [];
$selectedValue = '';
foreach ($spModes as $key => $label) {
if ($key === EnvSourceSpModeEnum::Shibboleth) {
$phpDelimiterMap[$key] = ';';
if ($vv_obj?->mva_delimiter == ';') {
$selectedValue = EnvSourceSpModeEnum::Shibboleth;
}
} elseif ($key === EnvSourceSpModeEnum::SimpleSamlPhp) {
$phpDelimiterMap[$key] = ',';
if ($vv_obj?->mva_delimiter == ',') {
$selectedValue = EnvSourceSpModeEnum::SimpleSamlPhp;
}
} elseif ($key === EnvSourceSpModeEnum::Other) {
$phpDelimiterMap[$key] = '';
if ($vv_obj?->mva_delimiter != '') {
$phpDelimiterMap[$key] = $vv_obj?->mva_delimiter;
$selectedValue = EnvSourceSpModeEnum::Other;
}
}
}

// Encode the array to JSON before inserting it into the Javascript block
$jsonDelimiterMap = json_encode($phpDelimiterMap);


$afterField = <<<JS
<script>
document.addEventListener('DOMContentLoaded', function() {
var select = document.getElementById('mva_delimiter_default');
var textbox = document.getElementById('mva_delimiter');
// Map the dropdown values to actual delimiter characters
var delimiterMap = $jsonDelimiterMap;
select.addEventListener('change', function() {
var selectedValue = select.value;
// Update the textbox with the corresponding delimiter
if (delimiterMap[selectedValue] !== undefined) {
textbox.value = delimiterMap[selectedValue];
} else {
// Fallback in case of unexpected values
textbox.value = selectedValue;
}
// Focus the textbox if "Other" is selected so we can immediately type
if (selectedValue === 'O') {
textbox.focus();
}
});
if (!textbox.value && select.value) {
textbox.value = delimiterMap[select.value] || '';
}
});
</script>
JS;


$fields = [
// 'duplicate_mode',
'sp_mode',
'mva_delimiter' => [
'fieldLabel' => __d('env_source','field.EnvSources.mva_delimiter'),
'groupedControls' => [
'mva_delimiter' => [
'type' => 'text',
'id' => 'mva_delimiter',
'label' => false,
'required' => true,
'class' => 'form-control mb-1',
'singleRowItem' => true,
],
'mva_delimiter_default' => [
'id' => 'mva_delimiter_default',
'label' => [
'text' => __d('env_source','field.EnvSources.mva_delimiter_common'),
'class' => 'mb-2'
],
'name' => 'mva_delimiter_default',
'required' => false,
'empty' => false,
'type' => 'select',
'value' => $selectedValue,
'options' => $spModes,
],
],
'afterField' => $afterField
],
'sync_on_login',
'address_type_id',
'default_affiliation_type_id',
Expand Down
5 changes: 3 additions & 2 deletions app/src/View/Helper/FieldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public function formField(string $fieldName,
string $fieldType = null,
array $fieldSelectOptions = null,
string $fieldNameAlias = null,
bool $labelIsTextOnly = null): string
bool $labelIsTextOnly = null): string
{
$fieldArgs = $fieldOptions ?? [];
$fieldArgs['label'] = $fieldOptions['label'] ?? false;
Expand Down Expand Up @@ -766,7 +766,8 @@ public function restructureFieldArguments(array $fieldArgs) {
'id',
'style',
'checked',
'label'
'label',
'name',
];

// Remove the top-level field options that are intended for Cake, and
Expand Down

0 comments on commit 74f7eee

Please sign in to comment.