mirror of
https://github.com/silverstripe/silverstripe-widgets
synced 2024-10-22 17:05:54 +02:00
6c91c62ec0
At the moment, when using Translatable on a site, if you use the Tranlate tab to create a translated version of the page, the WidgetAreaID is retained and you experience the same issue as reported in #58 Related to: #59
60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* Adds a single {@link WidgetArea} called "SideBar" to {@link Page} classes.
|
|
* Adjust your templates to render the resulting
|
|
* {@link WidgetArea} as required, through the $SideBarView placeholder.
|
|
*
|
|
* This extension is just an example on how to use the widgets functionality,
|
|
* feel free to create your own relationships, naming conventions, etc.
|
|
* without using this class.
|
|
*/
|
|
class WidgetPageExtension extends DataExtension {
|
|
|
|
private static $db = array(
|
|
'InheritSideBar' => 'Boolean',
|
|
);
|
|
|
|
private static $defaults = array(
|
|
'InheritSideBar' => true
|
|
);
|
|
|
|
private static $has_one = array(
|
|
'SideBar' => 'WidgetArea'
|
|
);
|
|
|
|
public function updateCMSFields(FieldList $fields) {
|
|
$fields->addFieldToTab(
|
|
"Root.Widgets",
|
|
new CheckboxField("InheritSideBar", 'Inherit Sidebar From Parent')
|
|
);
|
|
$fields->addFieldToTab(
|
|
"Root.Widgets",
|
|
new WidgetAreaEditor("SideBar")
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return WidgetArea
|
|
*/
|
|
public function SideBarView() {
|
|
if(
|
|
$this->owner->InheritSideBar
|
|
&& $this->owner->getParent()
|
|
&& $this->owner->getParent()->hasMethod('SideBar')
|
|
) {
|
|
return $this->owner->getParent()->SideBar();
|
|
} elseif($this->owner->SideBar()->exists()){
|
|
return $this->owner->SideBar();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Support Translatable so that we don't link WidgetAreas across translations
|
|
*/
|
|
public function onTranslatableCreate() {
|
|
//reset the sidebar ID
|
|
$this->owner->SideBarID = 0;
|
|
}
|
|
|
|
}
|