Skip to content

Commit

Permalink
Support widget forms with InheritSidebar
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hailwood authored and Matthew Hailwood committed Sep 22, 2015
1 parent c332a6a commit ff01783
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions code/controller/WidgetContentControllerExtension.php
Expand Up @@ -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;
}
Expand All @@ -51,7 +57,8 @@ public function handleWidget() {
break;
}

$widget = $this->owner->data()->$widgetAreaRelation()->Widgets(

$widget = $widgetOwner->$widgetAreaRelation()->Widgets(
sprintf('"Widget"."ID" = %d', $SQL_id)
)->First();
}
Expand Down

0 comments on commit ff01783

Please sign in to comment.