From ff0178330ad4f40092f6a161a58af22ebbaf16a3 Mon Sep 17 00:00:00 2001 From: Matthew Hailwood Date: Tue, 22 Sep 2015 10:23:00 +1200 Subject: [PATCH] Support widget forms with InheritSidebar Currently the system assumes that if a widget ends up at "handleWidget" that the widget resides on the current page. This patch checks if we are inheriting the sidebar and if so finds the top level page with the widget. --- .../WidgetContentControllerExtension.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/code/controller/WidgetContentControllerExtension.php b/code/controller/WidgetContentControllerExtension.php index ceb6281..a9ccee1 100644 --- a/code/controller/WidgetContentControllerExtension.php +++ b/code/controller/WidgetContentControllerExtension.php @@ -28,11 +28,17 @@ class WidgetContentControllerExtension extends Extension { public function handleWidget() { $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()->has_one(); - + $hasOnes = $widgetOwner->has_one(); + if(!$hasOnes) { return false; } @@ -51,7 +57,8 @@ class WidgetContentControllerExtension extends Extension { break; } - $widget = $this->owner->data()->$widgetAreaRelation()->Widgets( + + $widget = $widgetOwner->$widgetAreaRelation()->Widgets( sprintf('"Widget"."ID" = %d', $SQL_id) )->First(); }