mirror of
https://github.com/silverstripe/silverstripe-widgets
synced 2024-10-22 15:05:54 +00:00
Merge branch '1.1' into 1.2
This commit is contained in:
commit
1bbaba52e0
@ -26,17 +26,20 @@ class WidgetContentControllerExtension extends Extension
|
||||
* @return RequestHandler
|
||||
*/
|
||||
public function handleWidget()
|
||||
{
|
||||
$SQL_id = $this->owner->getRequest()->param('ID');
|
||||
if (!$SQL_id) {
|
||||
return false;
|
||||
{$SQL_id = $this->owner->getRequest()->param('ID');
|
||||
if(!$SQL_id) {return false;
|
||||
}
|
||||
/** @var SiteTree $widgetOwner */
|
||||
$widgetOwner = $this->owner->data();
|
||||
while($widgetOwner->InheritSideBar && $widgetOwner->Parent()->exists()){
|
||||
$widgetOwner = $widgetOwner->Parent();
|
||||
}
|
||||
|
||||
// find WidgetArea relations
|
||||
$widgetAreaRelations = array();
|
||||
$hasOnes = $this->owner->data()->hasOne();
|
||||
$hasOnes = $widgetOwner->hasOne();
|
||||
|
||||
if (!$hasOnes) {
|
||||
if(!$hasOnes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -54,7 +57,7 @@ class WidgetContentControllerExtension extends Extension
|
||||
break;
|
||||
}
|
||||
|
||||
$widget = $this->owner->data()->$widgetAreaRelation()->Widgets()
|
||||
$widget = $widgetOwner->$widgetAreaRelation()->Widgets()
|
||||
->filter('ID', $SQL_id)
|
||||
->First();
|
||||
}
|
||||
|
@ -54,19 +54,38 @@ class WidgetController extends Controller
|
||||
$id = ($this->widget) ? $this->widget->ID : null;
|
||||
$segment = Controller::join_links('widget', $id, $action);
|
||||
|
||||
if ($page = Director::get_current_page()) {
|
||||
return $page->Link($segment);
|
||||
$page = Director::get_current_page();
|
||||
if($page && !($page instanceof WidgetController)) {return $page->Link($segment);
|
||||
}
|
||||
|
||||
return Controller::curr()->Link($segment);
|
||||
if ($controller = $this->getParentController()) {return $controller->Link($segment);
|
||||
}
|
||||
|
||||
return $segment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cycles up the controller stack until it finds a non-widget controller
|
||||
* This is needed becauseController::currreturns the widget controller,
|
||||
* which means anyLinkfunction turns into endless loop.
|
||||
*
|
||||
* @return Controller
|
||||
*/
|
||||
public function getParentController()
|
||||
{
|
||||
foreach(Controller::$controller_stack as $controller) {
|
||||
if (!($controller instanceof WidgetController)) {
|
||||
return $controller;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Widget
|
||||
*/
|
||||
public function getWidget()
|
||||
{
|
||||
return $this->widget;
|
||||
{return $this->widget;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,8 +95,7 @@ class WidgetController extends Controller
|
||||
* @return string HTML
|
||||
*/
|
||||
public function Content()
|
||||
{
|
||||
return $this->renderWith(array_reverse(ClassInfo::ancestry($this->widget->class)));
|
||||
{return $this->renderWith(array_reverse(ClassInfo::ancestry($this->widget->class)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,8 +105,7 @@ class WidgetController extends Controller
|
||||
* @return string HTML
|
||||
*/
|
||||
public function WidgetHolder()
|
||||
{
|
||||
return $this->renderWith("WidgetHolder");
|
||||
{return $this->renderWith("WidgetHolder");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,19 +116,17 @@ class WidgetController extends Controller
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public function editablesegment()
|
||||
{
|
||||
public function editablesegment() {
|
||||
// use left and main to set the html config
|
||||
$leftandmain = LeftAndMain::create();
|
||||
$leftandmain->init();
|
||||
|
||||
$className = $this->urlParams['ID'];
|
||||
if (class_exists('Translatable') && Member::currentUserID()) {
|
||||
// set current locale based on logged in user's locale
|
||||
$locale = Member::currentUser()->Locale;
|
||||
i18n::set_locale($locale);
|
||||
}
|
||||
if (class_exists($className) && is_subclass_of($className, 'Widget')) {
|
||||
if(class_exists($className) && is_subclass_of($className, 'Widget')) {
|
||||
$obj = new $className();
|
||||
return $obj->EditableSegment();
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user