on 2021 Apr 07 11:42 AM
We are using a bunch of locales in our SAP Commerce instance. After updating to 20.05, our previous customization of changing the ordering not really works anymore, the localized values are now in random order (or at least I don't see any pattern):
Previously, it was possible to override the BackofficeLocaleService and rearrange the locales according to our needs. But now this method is used to get the locales, but the ordering is ignored. Is there any possiblility to change the order of the languages in the localized editor?
you need to extend com.hybris.cockpitng.editor.localized.LocalizedEditor and then in your custom editor you have to override getReadableLocales and getWriteableLocales methods
These method, in standard code, use HashSet which does not guarantee order. When you override them you have to, for the retained locales, sort them and then collect them into a Set implementation that retains order e.g LinkedHashSet
@Override
protected Set<Locale> getReadableLocales(final EditorContext editorContext)
{
return getLocales(editorContext.getReadableLocales());
}
@Override
protected Set<Locale> getWriteableLocales(final EditorContext editorContext)
{
return getLocales(editorContext.getWritableLocales());
}
private Set<Locale> getLocales(final Set<Locale> contextValue)
{
final Set<Locale> locales = Optional.ofNullable(contextValue)
.map(Sets::newHashSet)
.orElseGet(Sets::newHashSet);
final List<Locale> enabledDataLocales = getCockpitLocaleService().getEnabledDataLocales(getCockpitUserService().getCurrentUser());
locales.retainAll(enabledDataLocales);
return locales.stream()
// Sort & Use LinkedHashSet to retain order
// the call to this then ensures the session locale is rendered first
// followed by all other locales, based on the order of the set
.sorted(Comparator.comparing(Locale::toString))
.collect(Collectors.toCollection(LinkedHashSet::new));
}
After this you then need to create the definition.xml for your custom editor (basically copy the standard LocalizedEditor definition - below - and tweak it with your custom package and class name)
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved
-->
<editor-definition id="com.hybris.cockpitng.editor.localized" << change the id
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.hybris.com/schema/cockpitng/editor-definition.xsd">
<name>Localized Editor</name>
<description>Localized Editor</description>
<author>hybris</author> << change
<version>0.1</version>
<type>^Localized\((.*)\)$</type>
<editorClassName>com.hybris.cockpitng.editor.localized.LocalizedEditor</editorClassName> << change
<handlesLocalization>true</handlesLocalization>
</editor-definition>
then you have to register the editor (in backoffice spring file) as the default editor, so it overrides the standard one
<alias name="coreBackofficeEditorRegistry" alias="editorRegistry"/>
<bean id="coreBackofficeEditorRegistry" parent="simpleEditorRegistry">
<property name="defaultEditorMapping">
<map merge="true" key-type="java.lang.String" value-type="java.lang.String">
<entry key="^Localized\((.*)\)$" value=" TOUR CLASSNAME / EDITOR ID"/>
</map>
</property>
</bean>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
30 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.