From 59abb7db2ea072ea4ef99591ba4c616f43a3ee8d Mon Sep 17 00:00:00 2001 From: quasi Date: Tue, 22 Sep 2009 06:32:02 +0000 Subject: [PATCH] =?UTF-8?q?Multilanguage=20Korrektur=20f=C3=BCr=20RelatedL?= =?UTF-8?q?inks=20(und=20Links).=20Nun=20wird=20nicht=20mehr=20die=20Sprac?= =?UTF-8?q?hversion=20des=20ContentItems=20gespeichert,=20sondern=20das=20?= =?UTF-8?q?dazugeh=C3=B6rige=20ContentBundle.=20Bei=20der=20Anzeige=20wird?= =?UTF-8?q?=20dieses=20mit=20Hilfe=20von=20negotiate()=20in=20die=20gew?= =?UTF-8?q?=C3=BCnschte=20Sprachversion=20gewandelt,=20falls=20diese=20vor?= =?UTF-8?q?handen=20ist.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../com/arsdigita/cms/contenttypes/Link.java | 21 ++++++++++++++++++- .../cms/contenttypes/ui/LinkPropertyForm.java | 18 +++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/Link.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/Link.java index 440277152..eb31a1657 100755 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/Link.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/Link.java @@ -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; } /** diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/LinkPropertyForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/LinkPropertyForm.java index 2ead42b0b..cd54eea65 100755 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/LinkPropertyForm.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/LinkPropertyForm.java @@ -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;