mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
Unescape Form Fields POST data as Helper methode
Moved escaping or sent POST data into the Helper class since it is the same everywhere.
This commit is contained in:
parent
861d4128dc
commit
e7c7239ada
@ -235,9 +235,26 @@ class GridFieldBulkEditingHelper {
|
|||||||
return $formFieldsHTML;
|
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 )
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -335,7 +335,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
|
|||||||
*/
|
*/
|
||||||
public function update(SS_HTTPRequest $request)
|
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']);
|
$record = DataObject::get_by_id($this->gridField->list->dataClass, $data['ID']);
|
||||||
|
|
||||||
foreach($data as $field => $value)
|
foreach($data as $field => $value)
|
||||||
@ -361,7 +361,7 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
|
|||||||
*/
|
*/
|
||||||
public function cancel(SS_HTTPRequest $request)
|
public function cancel(SS_HTTPRequest $request)
|
||||||
{
|
{
|
||||||
$data = $this->getParsedPostData($request->requestVars());
|
$data = GridFieldBulkEditingHelper::unescapeFormFieldsPOSTData($request->requestVars());
|
||||||
$return = array();
|
$return = array();
|
||||||
|
|
||||||
$recordClass = $this->gridField->list->dataClass;
|
$recordClass = $this->gridField->list->dataClass;
|
||||||
@ -383,25 +383,6 @@ class GridFieldBulkImageUpload_Request extends RequestHandler {
|
|||||||
return $response;
|
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)
|
* Add a unique prefix to sensitive HTML attributes (ID, FOR, NAME)
|
||||||
* Fixes rendering issue (i.e. dropdown fields) and IDs being mistaken for page IDs
|
* Fixes rendering issue (i.e. dropdown fields) and IDs being mistaken for page IDs
|
||||||
|
@ -162,7 +162,7 @@ class GridFieldBulkManager_Request extends RequestHandler {
|
|||||||
*/
|
*/
|
||||||
public function update(SS_HTTPRequest $request)
|
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']);
|
$record = DataObject::get_by_id($this->gridField->list->dataClass, $data['ID']);
|
||||||
|
|
||||||
foreach($data as $field => $value)
|
foreach($data as $field => $value)
|
||||||
@ -234,28 +234,6 @@ class GridFieldBulkManager_Request extends RequestHandler {
|
|||||||
return $recordList['records'];
|
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
|
* Edited version of the GridFieldEditForm function
|
||||||
* adds the 'Bulk Upload' at the end of the crums
|
* adds the 'Bulk Upload' at the end of the crums
|
||||||
|
Loading…
Reference in New Issue
Block a user