Multilanguage Korrektur für RelatedLinks (und Links). Nun wird nicht mehr die Sprachversion des ContentItems gespeichert, sondern das dazugehörige ContentBundle. Bei der Anzeige wird dieses mit Hilfe von negotiate() in die gewünschte Sprachversion gewandelt, falls diese vorhanden ist.

Es sollte ebenfalls noch mit den alten Inhalten in der DB funktionieren, allerdings wird dann keine Sprachvariante ermittelt (altes Verhalten).

Problematisch kann sein, daß Links nun automatisch in eine andere Sprachversion wechseln, falls die gewünschte Variante nicht vorhanden ist. Ich bin mir noch nicht sicher, ob die Standardversion des ContentItems zurückgegeben wird, wenn keine Übereinstimmung gefunden werden kann, oder ob der Link dann entfällt.

git-svn-id: https://svn.libreccm.org/ccm/trunk@265 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2009-09-22 06:32:02 +00:00
parent 790962b065
commit 59abb7db2e
2 changed files with 37 additions and 2 deletions

View File

@ -20,9 +20,11 @@ package com.arsdigita.cms.contenttypes;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.dispatcher.ItemResolver;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.kernel.ACSObject;
@ -193,7 +195,24 @@ public class Link extends ACSObject {
*/
public ContentItem getTargetItem() {
DataObject object = (DataObject)get(TARGET_ITEM);
return (ContentItem)DomainObjectFactory.newInstance(object);
ACSObject acsObject = (ACSObject) DomainObjectFactory.newInstance(object);
// Quasimodo: BEGIN
// This is part of the patch to make RelatedLink (and Link) multilanguage compatible
// Here we have to check if the target item is a content bundle, so we have to negotiate the language
// If we don't do this, all related links would come back as type ContentBundle'instead of the actual
// content type
ContentItem ci;
// If acsObject is instance of ContentBundle
if(acsObject instanceof ContentBundle) {
// get the negotiated language version of this ContentBundle
ci = ((ContentBundle) acsObject).negotiate(DispatcherHelper.getRequest().getLocales());
} else {
// else there are no language versions so just use the acsObject
ci = (ContentItem) acsObject;
}
// Quasimodo: END
return ci;
}
/**

View File

@ -39,6 +39,7 @@ import com.arsdigita.bebop.form.CheckboxGroup;
import com.arsdigita.bebop.form.TextArea;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.cms.ContentBundle;
import com.arsdigita.util.Assert;
import com.arsdigita.util.UncheckedWrapperException;
import com.arsdigita.web.Web;
@ -455,7 +456,22 @@ public class LinkPropertyForm extends FormSection
} else {
// Internal
link.setTargetURI(null);
link.setTargetItem((ContentItem) data.get(ITEM_SEARCH));
// Quasimodo: BEGIN
// This is part of the patch to make RelatedLink (and Link) multilanguage compatible
// Here we have to link to the content bundle instead of the content item, if there's one
// else we don't have a proper multilanguage support'
ContentItem ci = (ContentItem) data.get(ITEM_SEARCH);
// If the selected target item ci has a parent of type ContentBundle
if (ci.getParent() instanceof ContentBundle) {
// Then there a multiple language versions of this content item and we want to
// link to the content bundle, so we can later negotiate the language depending
// on browser settings
ci = (ContentItem) ci.getParent();
}
link.setTargetItem(ci);
}
// Process whether link is to be opened in new window
boolean isNewWindow = false;