When using the code below for a widget in a site with translations,
the widget for a page in one language will be shared across all translated pages - this means that when on a translated page the widget possibly links to a page not in the same locale
is there any known fix for this?
class LinkWidget extends Widget
{
static $db = array(
'LinkPage' => 'Text',
);
static $has_one = array(
'LinkToSiteTree' => 'SiteTree',
);
function LinkToPage(){
$strURL = '';
if (isset($this->LinkToSiteTreeID) && is_numeric($this->LinkToSiteTreeID)){
$page = DataObject::get_by_id('SiteTree',$this->LinkToSiteTreeID);
if ($page){
$strURL = $this->BaseHref().$page->RelativeLink();
}
}
return $strURL;
}
}
//template
<a href="{$LinkToPage}"></a>
However each widget will link to the page one page in one language. for example, if I had a site with 2 translation (English and German) if i add a widget to a English page linking it to another English page, then the German translation of this page will also have that widget with the same image as the engliah page and it will link to the english page instead of the translated German page.