Skip to content

Commit

Permalink
Add file field type
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic Tubach committed Sep 23, 2024
1 parent 38eff83 commit 0261d4f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ public function getFieldTypes(): iterable {
break;

case 'RichTextEditor':
// fall through
// not supported
break;

Check failure on line 132 in Civi/RemoteEventFormEditor/FieldType/Loader/AbstractCustomFieldTypeLoader.php

View workflow job for this annotation

GitHub Actions / PHP_CodeSniffer

Case breaking statements must be followed by a single blank line
case 'EntityRef':
// fall through
case 'File':
// not supported
break;

Check failure on line 135 in Civi/RemoteEventFormEditor/FieldType/Loader/AbstractCustomFieldTypeLoader.php

View workflow job for this annotation

GitHub Actions / PHP_CodeSniffer

Case breaking statements must be followed by a single blank line
case 'File':
yield new EditorFieldType($identifier, 'file', $label, $initialData);
break;

default:
$this->logger->info(sprintf('Unknown input type "%s"', $field['input_type']));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function createFields(
[$entityName, $entityFieldName] = explode(':', $editorField['target'], 2);
$fieldName = FormFieldNameUtil::toProfileFormFieldName($editorField['target']);

return [
$fields = [
$fieldName => [
'name' => $fieldName,
'entity_name' => $entityName,
Expand All @@ -58,13 +58,21 @@ public function createFields(
'required' => ($editorField['required'] ?? FALSE) === TRUE ? 1 : 0,
'label' => $editorField['label'],
'description' => $editorField['description'] ?? NULL,
'maxlength' => $editorField['maxLength'] ?? NULL,
'validation' => $this->getValidation($editorField, $editorFieldType),
'value' => $editorField['value'] ?? NULL,
'parent' => $parent,
'dependencies' => DependentFieldNameUtil::getDependentProfileFormFieldNames($editorField),
],
];

if ('file' === $editorFieldType->getInput()) {
$fields[$fieldName]['max_filesize'] = $editorField['maxFilesize'] ?? NULL;
}
else {
$fields[$fieldName]['maxlength'] = $editorField['maxLength'] ?? NULL;
}

return $fields;
}

/**
Expand All @@ -77,6 +85,7 @@ public function isSupported(array $editorField, EditorFieldType $editorFieldType
'date',
'datetime',
'checkbox',
'file',
], TRUE);
}

Expand All @@ -100,6 +109,9 @@ private function getType(array $editorField, EditorFieldType $editorFieldType):
case 'checkbox':
return 'Checkbox';

case 'file':
return 'File';

default:
throw new \InvalidArgumentException(sprintf('Unsupported input type "%s"', $editorFieldType->getInput()));
}
Expand Down
11 changes: 11 additions & 0 deletions ang/crmRemoteEventFormEditor/field-types/file.template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="control form-group">
<label for="field-target-{{ngModelItem._id}}">{{ ts('Target') }}</label>
<input id="field-target-{{ngModelItem._id}}" class="form-control" type="text" ng-model="ngModelItem.target" ng-required="true">
</div>
<div class="control form-group">
<label for="field-max-filesize-{{ngModelItem._id}}">{{ ts('Maximum Length in Bytes') }}</label>
<input id="field-max-filesize-{{ngModelItem._id}}" class="form-control" type="number" min="1" ng-model="ngModelItem.maxFilesize">
</div>
<div>
{{ ts('An existing file cannot be removed on update, only be replaced by a new one.') }}
</div>
Binary file modified l10n/de_DE/LC_MESSAGES/remoteeventformeditor.mo
Binary file not shown.
12 changes: 12 additions & 0 deletions l10n/de_DE/LC_MESSAGES/remoteeventformeditor.po
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ msgstr "Optional"
#: ang/crmRemoteEventFormEditor/field-types/checkbox.template.html
#: ang/crmRemoteEventFormEditor/field-types/date.template.html
#: ang/crmRemoteEventFormEditor/field-types/datetime.template.html
#: ang/crmRemoteEventFormEditor/field-types/file.template.html
#: ang/crmRemoteEventFormEditor/field-types/location-type.template.html
#: ang/crmRemoteEventFormEditor/field-types/multi-select.template.html
#: ang/crmRemoteEventFormEditor/field-types/number.template.html
Expand All @@ -242,6 +243,17 @@ msgstr "Initial gesetzt"
msgid "Initial Value"
msgstr "Initialer Wert"

#: ang/crmRemoteEventFormEditor/field-types/file.template.html
msgid "Maximum Length in Bytes"
msgstr "Maximale Länge in Bytes"

#: ang/crmRemoteEventFormEditor/field-types/file.template.html
msgid ""
"An existing file cannot be removed on update, only be replaced by a new one."
msgstr ""
"Eine existierende Datei kann beim Aktualisieren nicht entfernt, sondern nur "
"durch eine neue ersetzt werden."

#: ang/crmRemoteEventFormEditor/field-types/location-type.template.html
msgid "Hidden"
msgstr "Versteckt"
Expand Down
10 changes: 9 additions & 1 deletion l10n/remoteeventformeditor.pot
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ msgstr ""
msgid "Optional"
msgstr ""

#: ang/crmRemoteEventFormEditor/field-types/checkbox.template.html ang/crmRemoteEventFormEditor/field-types/date.template.html ang/crmRemoteEventFormEditor/field-types/datetime.template.html ang/crmRemoteEventFormEditor/field-types/location-type.template.html ang/crmRemoteEventFormEditor/field-types/multi-select.template.html ang/crmRemoteEventFormEditor/field-types/number.template.html ang/crmRemoteEventFormEditor/field-types/select.template.html ang/crmRemoteEventFormEditor/field-types/text.template.html
#: ang/crmRemoteEventFormEditor/field-types/checkbox.template.html ang/crmRemoteEventFormEditor/field-types/date.template.html ang/crmRemoteEventFormEditor/field-types/datetime.template.html ang/crmRemoteEventFormEditor/field-types/file.template.html ang/crmRemoteEventFormEditor/field-types/location-type.template.html ang/crmRemoteEventFormEditor/field-types/multi-select.template.html ang/crmRemoteEventFormEditor/field-types/number.template.html ang/crmRemoteEventFormEditor/field-types/select.template.html ang/crmRemoteEventFormEditor/field-types/text.template.html
msgid "Target"
msgstr ""

Expand All @@ -190,6 +190,14 @@ msgstr ""
msgid "Initial Value"
msgstr ""

#: ang/crmRemoteEventFormEditor/field-types/file.template.html
msgid "Maximum Length in Bytes"
msgstr ""

#: ang/crmRemoteEventFormEditor/field-types/file.template.html
msgid "An existing file cannot be removed on update, only be replaced by a new one."
msgstr ""

#: ang/crmRemoteEventFormEditor/field-types/location-type.template.html
msgid "Hidden"
msgstr ""
Expand Down

0 comments on commit 0261d4f

Please sign in to comment.