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;