Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
8cd29d4
LPD-49643 Rename isLocalizable to isLocalizationSupported and apply d…
igor-franca Mar 21, 2025
5e68161
LPD-49643 Expose necessary properties in DDM fields context contributor
igor-franca Mar 21, 2025
86ea88b
LPD-49643 buildService
igor-franca Mar 28, 2025
0526980
LPD-49643 Create language keys
igor-franca Mar 12, 2025
6784c47
LPD-49643 Build Lang
igor-franca Mar 12, 2025
50a934d
LPD-49643 Use the isLocalizationSupported property to decide the idea…
igor-franca Mar 12, 2025
e5417c8
LPD-49643 Skip evaluation when editingLanguageId is different from de…
igor-franca Mar 19, 2025
ccb5eb2
LPD-51511 Use containerId to validate whether to send the default lan…
larissacribeiro Mar 20, 2025
b03505b
LPD-49643 Fix display name
igor-franca Mar 20, 2025
f99b85b
LPD-49643 Remove unused file
igor-franca Mar 21, 2025
ce7fcf9
LPD-49643 Set editingLanguageId using the default language of the obj…
igor-franca Mar 25, 2025
1d58e88
LPD-49643 Expect errors in the default language of the form, in this …
igor-franca Mar 25, 2025
de811ad
LPD-49643 use nameMap to get listTypeEntries options labels
larissacribeiro Mar 31, 2025
abb3e6f
LPD-49643 fix: remove initial values from AutoIncrementObjectFieldBus…
MarinhoFeliphe Apr 1, 2025
b1f5809
LPD-49643 Fill 'DDMFormFieldOptions' default locale
pedro-oliveira446 Apr 2, 2025
0e4e64d
LPD-49643 Extract to Util class
pedro-oliveira446 Apr 2, 2025
6243332
LPD-49643 Reuse to single select
pedro-oliveira446 Apr 2, 2025
5a09182
LPD-49643 Add default locale parameter in the json
pedro-oliveira446 Apr 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {useFormState} from './useForm.es';
* the `evaluate` function.
*/
export function useEvaluate(thunk) {
const {groupId, portletNamespace} = useConfig();
const {containerId, groupId, portletNamespace} = useConfig();
const {
defaultLanguageId,
editingLanguageId,
Expand All @@ -27,6 +27,7 @@ export function useEvaluate(thunk) {
return useCallback(
(args) =>
thunk({
containerId,
defaultLanguageId,
editingLanguageId,
groupId,
Expand All @@ -38,6 +39,7 @@ export function useEvaluate(thunk) {
...args,
}),
[
containerId,
defaultLanguageId,
editingLanguageId,
groupId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ import {evaluate, mergePages} from '../../utils/evaluation.es';
import {PagesVisitor} from '../../utils/visitors.es';
import {EVENT_TYPES} from '../actions/eventTypes.es';
import {disableSubmitButton} from '../utils/submitButtonController.es';

let REVALIDATE_UPDATES = [];

const skipPageEvaluationFieldNames = ['name', 'requiredErrorMessage'];

const needsPageEvaluation = (fieldName) => {
const needsPageEvaluation = (
containerId,
defaultLanguageId,
editingLanguageId,
fieldName
) => {
if (containerId === 'editObjectEntry') {
return editingLanguageId === defaultLanguageId;
}

return !skipPageEvaluationFieldNames.includes(fieldName);
};

Expand Down Expand Up @@ -59,6 +67,7 @@ const getEditedPages = ({
let lastEditedPages = [];

export default function fieldChange({
containerId,
defaultLanguageId,
editingLanguageId,
focusedField,
Expand Down Expand Up @@ -107,7 +116,16 @@ export default function fieldChange({
}
}

if (evaluable && (viewMode || needsPageEvaluation(fieldName))) {
if (
evaluable &&
(viewMode ||
needsPageEvaluation(
containerId,
defaultLanguageId,
editingLanguageId,
fieldName
))
) {
try {
disableSubmitButton(submitButtonId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {EVENT_TYPES} from '../actions/eventTypes.es';

export default function formValidate({
activePage,
containerId,
defaultLanguageId,
editingLanguageId,
formId,
Expand All @@ -26,6 +27,7 @@ export default function formValidate({
}

return evaluate(null, {
containerId,
defaultLanguageId,
editingLanguageId,
formId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ const usePublicAPI = ({apiRef, containerRef, unstable_onEventRef}) => {
dispatch(
formValidate({
activePage,
containerId,
defaultLanguageId,
editingLanguageId,
formId: containerRef.current
Expand All @@ -268,6 +269,7 @@ const usePublicAPI = ({apiRef, containerRef, unstable_onEventRef}) => {
})
),
[
containerId,
dispatch,
activePage,
containerRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ interface DataDefinitionCustomProperties {
}

export interface Field<T = unknown> {
editOnlyInDefaultLanguage?: boolean;
fieldName: string;
localizable?: boolean;
localizedObjectField?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export function mergePages(

const doEvaluate = debounce((fieldName, evaluatorContext, callback) => {
const {
containerId,
defaultLanguageId,
editingLanguageId,
formId,
Expand All @@ -153,7 +154,10 @@ const doEvaluate = debounce((fieldName, evaluatorContext, callback) => {

makeFetch({
body: convertToFormData({
languageId: editingLanguageId,
languageId:
containerId === 'editObjectEntry'
? defaultLanguageId
: editingLanguageId,
p_auth: Liferay.authToken,
p_l_id: themeDisplay.getPlid(),
p_v_l_s_g_id: themeDisplay.getSiteGroupId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@

package com.liferay.dynamic.data.mapping.util;

import com.liferay.dynamic.data.mapping.model.DDMFormField;
import com.liferay.dynamic.data.mapping.model.DDMFormFieldOptions;
import com.liferay.dynamic.data.mapping.model.LocalizedValue;
import com.liferay.list.type.model.ListTypeEntry;
import com.liferay.list.type.service.ListTypeEntryLocalService;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.json.JSONUtil;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.HashMapBuilder;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.StringUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

Expand All @@ -26,12 +28,69 @@
*/
public class DDMFormFieldTemplateContextContributorUtil {

public static Map<Locale, String> getListTypeEntryNameMap(
DDMFormField ddmFormField, String key,
public static Map<String, Object> getLocaleMap(Locale defaultLocale) {
JSONObject localeJSONObject = _getLocaleJSONObject(defaultLocale);

return HashMapBuilder.<String, Object>put(
"availableLocales",
JSONUtil.toJSONArray(
LanguageUtil.getAvailableLocales(),
locale -> _getLocaleJSONObject(locale), _log)
).put(
"defaultLocale", localeJSONObject
).put(
"editingLocale", localeJSONObject
).build();
}

public static List<Map<String, Object>> getOptions(
DDMFormFieldOptions ddmFormFieldOptions, Long listTypeDefinitionId,
ListTypeEntryLocalService listTypeEntryLocalService) {

long listTypeDefinitionId = GetterUtil.getLong(
ddmFormField.getProperty("listTypeDefinitionId"));
List<Map<String, Object>> options = new ArrayList<>();

for (String optionValue : ddmFormFieldOptions.getOptionsValues()) {
if (optionValue == null) {
continue;
}

LocalizedValue localizedValue = ddmFormFieldOptions.getOptionLabels(
optionValue);

options.add(
HashMapBuilder.<String, Object>put(
"defaultLocale",
String.valueOf(localizedValue.getDefaultLocale())
).put(
"label",
localizedValue.getString(localizedValue.getDefaultLocale())
).put(
"labelMap",
() -> {
Map<Locale, String> labeMap = _getListTypeEntryNameMap(
optionValue, listTypeDefinitionId,
listTypeEntryLocalService);

if (labeMap != null) {
return labeMap;
}

return localizedValue.getValues();
}
).put(
"reference",
ddmFormFieldOptions.getOptionReference(optionValue)
).put(
"value", optionValue
).build());
}

return options;
}

private static Map<Locale, String> _getListTypeEntryNameMap(
String key, long listTypeDefinitionId,
ListTypeEntryLocalService listTypeEntryLocalService) {

if (listTypeDefinitionId == 0) {
return null;
Expand All @@ -48,21 +107,6 @@ public static Map<Locale, String> getListTypeEntryNameMap(
return listTypeEntry.getNameMap();
}

public static Map<String, Object> getLocaleMap(Locale defaultLocale) {
JSONObject localeJSONObject = _getLocaleJSONObject(defaultLocale);

return HashMapBuilder.<String, Object>put(
"availableLocales",
JSONUtil.toJSONArray(
LanguageUtil.getAvailableLocales(),
locale -> _getLocaleJSONObject(locale), _log)
).put(
"defaultLocale", localeJSONObject
).put(
"editingLocale", localeJSONObject
).build();
}

private static JSONObject _getLocaleJSONObject(Locale locale) {
String languageId = LocaleUtil.toLanguageId(locale);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public Map<String, Object> getParameters(
ddmFormField.getProperty("localizedObjectField"));

return HashMapBuilder.<String, Object>put(
"editOnlyInDefaultLanguage",
GetterUtil.getBoolean(
ddmFormField.getProperty("editOnlyInDefaultLanguage"))
).put(
"isLocalizationSupported",
GetterUtil.getBoolean(
ddmFormField.getProperty("isLocalizationSupported"))
).put(
"localizedObjectField", localizedObjectField
).put(
"predefinedValue",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,20 @@ public Map<String, Object> getParameters(
ddmFormField.getProperty("localizedObjectField"));

return HashMapBuilder.<String, Object>put(
"editOnlyInDefaultLanguage",
GetterUtil.getBoolean(
ddmFormField.getProperty("editOnlyInDefaultLanguage"))
).put(
"firstDayOfWeek",
_getFirstDayOfWeek(ddmFormFieldRenderingContext.getLocale())
).put(
"htmlAutocompleteAttribute",
GetterUtil.getString(
ddmFormField.getProperty("htmlAutocompleteAttribute"))
).put(
"isLocalizationSupported",
GetterUtil.getBoolean(
ddmFormField.getProperty("isLocalizationSupported"))
).put(
"localizedObjectField", localizedObjectField
).put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public Map<String, Object> getParameters(

if (ddmFormFieldRenderingContext.isReturnFullContext()) {
parameters.put("displayStyle", _getDisplayStyle(ddmFormField));
parameters.put(
"editOnlyInDefaultLanguage",
GetterUtil.getBoolean(
ddmFormField.getProperty("editOnlyInDefaultLanguage")));
parameters.put(
"isLocalizationSupported",
GetterUtil.getBoolean(
ddmFormField.getProperty("isLocalizationSupported")));
parameters.put(
"placeholder",
_getPlaceholder(ddmFormField, ddmFormFieldRenderingContext));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,21 @@ public Map<String, Object> getParameters(
"dataType", dataType
).put(
"direction", ddmFormField.getProperty("direction")
).put(
"editOnlyInDefaultLanguage",
GetterUtil.getBoolean(
ddmFormField.getProperty("editOnlyInDefaultLanguage"))
).put(
"hideField",
GetterUtil.getBoolean(ddmFormField.getProperty("hideField"))
).put(
"htmlAutocompleteAttribute",
GetterUtil.getString(
ddmFormField.getProperty("htmlAutocompleteAttribute"))
).put(
"isLocalizationSupported",
GetterUtil.getBoolean(
ddmFormField.getProperty("isLocalizationSupported"))
).put(
"localizedObjectField", localizedObjectField
).put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public Map<String, Object> getParameters(
ddmFormField.getProperty("localizedObjectField"));

return HashMapBuilder.<String, Object>put(
"editOnlyInDefaultLanguage",
GetterUtil.getBoolean(
ddmFormField.getProperty("editOnlyInDefaultLanguage"))
).put(
"isLocalizationSupported",
GetterUtil.getBoolean(
ddmFormField.getProperty("isLocalizationSupported"))
).put(
"localizedObjectField", localizedObjectField
).put(
"predefinedValue",
Expand Down
Loading