Search in sources :

Example 1 with MultiOptionQuestionForm

use of forms.MultiOptionQuestionForm in project civiform by seattle-uat.

the class AdminQuestionController method updateDefaultLocalizations.

/**
 * The edit form can change the default locale's text - we want to only change the default locale
 * text, instead of overwriting all localizations.
 */
private void updateDefaultLocalizations(QuestionDefinition existing, QuestionDefinitionBuilder updated, QuestionForm questionForm) {
    // Instead of overwriting all localizations, we just want to overwrite the one
    // for the default locale (the only one possible to change in the edit form).
    updated.setQuestionText(existing.getQuestionText().updateTranslation(LocalizedStrings.DEFAULT_LOCALE, questionForm.getQuestionText()));
    // all translations of it.
    if (questionForm.getQuestionHelpText().isBlank()) {
        updated.setQuestionHelpText(LocalizedStrings.empty());
    } else {
        updated.setQuestionHelpText(existing.getQuestionHelpText().updateTranslation(LocalizedStrings.DEFAULT_LOCALE, questionForm.getQuestionHelpText()));
    }
    if (existing.getQuestionType().equals(QuestionType.ENUMERATOR)) {
        updateDefaultLocalizationForEntityType(updated, (EnumeratorQuestionDefinition) existing, ((EnumeratorQuestionForm) questionForm).getEntityType());
    }
    if (questionForm instanceof MultiOptionQuestionForm) {
        MultiOptionQuestionDefinition definition = null;
        try {
            definition = (MultiOptionQuestionDefinition) questionForm.getBuilder().build();
        } catch (UnsupportedQuestionTypeException e) {
            // Impossible - we checked the type above.
            throw new RuntimeException(e);
        }
        updateDefaultLocalizationForOptions(updated, (MultiOptionQuestionDefinition) existing, definition.getOptions());
    }
}
Also used : MultiOptionQuestionForm(forms.MultiOptionQuestionForm) UnsupportedQuestionTypeException(services.question.exceptions.UnsupportedQuestionTypeException) MultiOptionQuestionDefinition(services.question.types.MultiOptionQuestionDefinition)

Aggregations

MultiOptionQuestionForm (forms.MultiOptionQuestionForm)1 UnsupportedQuestionTypeException (services.question.exceptions.UnsupportedQuestionTypeException)1 MultiOptionQuestionDefinition (services.question.types.MultiOptionQuestionDefinition)1