diff --git a/code/GridFieldBulkEditingHelper.php b/code/GridFieldBulkEditingHelper.php index c44b9ea..ed00fdb 100644 --- a/code/GridFieldBulkEditingHelper.php +++ b/code/GridFieldBulkEditingHelper.php @@ -235,9 +235,26 @@ class GridFieldBulkEditingHelper { return $formFieldsHTML; } + /** + * Simple function that replace the 'record_XX_' off of the ID field name + * prefix needed since it was taken for a pageID if sent as is as well as fixing other things + * + * @param array $data + * @return array + */ public static function unescapeFormFieldsPOSTData ( $requestVars ) { - //@todo + $return = array(); + + foreach( $requestVars as $key => $val) + { + $return[ preg_replace( '/record_(\d+)_(\w+)/i', '$2', $key) ] = $val; + } + + if ( isset($return['url']) ) unset($return['url']); + if ( isset($return['cacheBuster']) ) unset($return['cacheBuster']); + + return $return; } diff --git a/code/GridFieldBulkImageUpload_Request.php b/code/GridFieldBulkImageUpload_Request.php index 5bdaeca..f8ee912 100644 --- a/code/GridFieldBulkImageUpload_Request.php +++ b/code/GridFieldBulkImageUpload_Request.php @@ -335,7 +335,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { */ public function update(SS_HTTPRequest $request) { - $data = $this->getParsedPostData($request->requestVars()); + $data = GridFieldBulkEditingHelper::unescapeFormFieldsPOSTData($request->requestVars()); $record = DataObject::get_by_id($this->gridField->list->dataClass, $data['ID']); foreach($data as $field => $value) @@ -361,7 +361,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { */ public function cancel(SS_HTTPRequest $request) { - $data = $this->getParsedPostData($request->requestVars()); + $data = GridFieldBulkEditingHelper::unescapeFormFieldsPOSTData($request->requestVars()); $return = array(); $recordClass = $this->gridField->list->dataClass; @@ -382,25 +382,6 @@ class GridFieldBulkImageUpload_Request extends RequestHandler { $response->addHeader('Content-Type', 'text/plain'); return $response; } - - /** - * Simple function that replace the 'record_XX_' off of the ID field name - * prefix needed since it was taken for a pageID if sent as is as well as fixing other things - * - * @param array $data - * @return array - */ - function getParsedPostData(array $data) - { - $return = array(); - - foreach( $data as $key => $val) - { - $return[ preg_replace( '/record_(\d+)_(\w+)/i', '$2', $key) ] = $val; - } - - return $return; - } /** * Add a unique prefix to sensitive HTML attributes (ID, FOR, NAME) diff --git a/code/GridFieldBulkManager_Request.php b/code/GridFieldBulkManager_Request.php index 04994e3..f238e17 100644 --- a/code/GridFieldBulkManager_Request.php +++ b/code/GridFieldBulkManager_Request.php @@ -162,7 +162,7 @@ class GridFieldBulkManager_Request extends RequestHandler { */ public function update(SS_HTTPRequest $request) { - $data = $this->getParsedPostData($request->requestVars()); + $data = GridFieldBulkEditingHelper::unescapeFormFieldsPOSTData($request->requestVars()); $record = DataObject::get_by_id($this->gridField->list->dataClass, $data['ID']); foreach($data as $field => $value) @@ -234,28 +234,6 @@ class GridFieldBulkManager_Request extends RequestHandler { return $recordList['records']; } - /** - * Simple function that replace the 'record_XX_' off of the ID field name - * prefix needed since it was taken for a pageID if sent as is as well as fixing other things - * - * @param array $data - * @return array - */ - function getParsedPostData(array $data) - { - $return = array(); - - foreach( $data as $key => $val) - { - $return[ preg_replace( '/record_(\d+)_(\w+)/i', '$2', $key) ] = $val; - } - - if ( isset($return['url']) ) unset($return['url']); - if ( isset($return['cacheBuster']) ) unset($return['cacheBuster']); - - return $return; - } - /** * Edited version of the GridFieldEditForm function * adds the 'Bulk Upload' at the end of the crums