Skip to content

Commit

Permalink
Fixed url not triming correctly
Browse files Browse the repository at this point in the history
Added workaround for gridfield state's not carrying over
  • Loading branch information
UndefinedOffset committed Jun 12, 2014
1 parent 8c4f751 commit 0a6d5b7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
7 changes: 7 additions & 0 deletions code/extensions/AdvancedWidgetEditorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public function AdvancedCMSEditor() {

$field->setName($name);


//Fix the gridstate field
if($field instanceof GridField) {
$field->getState(false)->setName($name.'[GridState]');
}


$outputFields->push($field);
}

Expand Down
36 changes: 32 additions & 4 deletions code/forms/AdvancedWidgetAreaEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public function handleField($request) {
}


//@TODO Something is wrong with deleting a file in upload field (routing issue?)
$field=$obj->getCMSFields()->dataFieldByName($realFieldName);
if($field) {
$field->setForm($this->getFormShiv($obj));
Expand All @@ -129,6 +128,12 @@ public function handleField($request) {
$this->request->shift(substr_count($this->request->remaining(), '/')+1);

$field->setName('Widget['.$this->getName().']['.$objId.']['.$field->getName().']');

//Fix the gridstate field
if($field instanceof GridField) {
$field->getState(false)->setName($field->getName().'[GridState]');
}

return $field->handleRequest($request, $this->model);
}else {
// falling back to fieldByName, e.g. for getting tabs
Expand All @@ -142,6 +147,12 @@ public function handleField($request) {
$this->request->shift(substr_count($this->request->remaining(), '/')+1);

$field->setName('Widget['.$this->getName().']['.$objId.']['.$field->getName().']');

//Fix the gridstate field
if($field instanceof GridField) {
$field->getState(false)->setName($field->getName().'[GridState]');
}

return $field->handleRequest($request, $this->model);
}
}
Expand Down Expand Up @@ -199,15 +210,20 @@ protected function getFakeRequest(SS_HTTPRequest $request, Widget $sourceWidget,
unset($finalPostVars['Widget']);


//Workaround for UploadField's confusing the request
//Workaround for UploadField's and GridFields confusing the request
$fields=$sourceWidget->getCMSFields();
$uploadFields=array();
$gridFields=array();
foreach($fields as $field) {
if($field instanceof UploadField) {
$uploadFields[]=$field->getName();
}else if($field instanceof GridField) {
$gridFields[]=$field->getName();
}
}


//Re-orgazine the upload field data
if(count($uploadFields)) {
foreach($uploadFields as $field) {
$formFieldName='Widget['.$this->getName().']['.$objID.']['.$field.']';
Expand Down Expand Up @@ -236,16 +252,28 @@ protected function getFakeRequest(SS_HTTPRequest $request, Widget $sourceWidget,
}


//Reorganize the gridfield data
if(count($gridFields)) {
foreach($gridFields as $field) {
$formFieldName='Widget['.$this->getName().']['.$objID.']['.$field.']';
$fieldData=array(
$formFieldName=>$postVars['Widget'][$this->getName()][$objID][$field]
);
}

$finalPostVars=array_merge_recursive($finalPostVars, $fieldData);
}


$headers=$request->getHeaders();
$request=new SS_HTTPRequest($_SERVER['REQUEST_METHOD'], str_replace($baseLink, '', $request->getURL()), $request->getVars(), $finalPostVars, $request->getBody());
$request=new SS_HTTPRequest($_SERVER['REQUEST_METHOD'], str_replace(rtrim($baseLink, '/'), '', rtrim($request->getURL(), '/')).'/', $request->getVars(), $finalPostVars, $request->getBody());
$request->match('$Action/$ID/$OtherID');

//Merge in the headers
foreach($headers as $header=>$value) {
$request->addHeader($header, $value);
}


return $request;
}

Expand Down

0 comments on commit 0a6d5b7

Please sign in to comment.