mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
get a record's fields + fields name escaping
Possibility to get a specific record's pre-populated fields and added function to escape formFields names when they are not converted ot html yet
This commit is contained in:
parent
92d269bac3
commit
5e743abeb9
@ -3,18 +3,33 @@
|
|||||||
* Generic helper class for the various bulk editing component
|
* Generic helper class for the various bulk editing component
|
||||||
* contains common functions
|
* contains common functions
|
||||||
*
|
*
|
||||||
|
* @todo clean up functions names: makes them consistent and more explicit
|
||||||
|
*
|
||||||
* @author colymba
|
* @author colymba
|
||||||
* @package GridFieldBulkEditingTools
|
* @package GridFieldBulkEditingTools
|
||||||
*/
|
*/
|
||||||
class GridFieldBulkEditingHelper {
|
class GridFieldBulkEditingHelper {
|
||||||
//put your code here
|
//put your code here
|
||||||
|
|
||||||
public static function getModelCMSDataFields ( $config, $modelClass )
|
public static function getModelCMSDataFields ( $config, $modelClass, $recordID = null )
|
||||||
{
|
{
|
||||||
$cmsFields = singleton($modelClass)->getCMSFields();
|
if ( $recordID == null ) $cmsFields = singleton($modelClass)->getCMSFields();
|
||||||
|
else $cmsFields = DataObject::get_by_id($modelClass, $recordID)->getCMSFields();
|
||||||
|
|
||||||
$cmsDataFields = $cmsFields->dataFields();
|
$cmsDataFields = $cmsFields->dataFields();
|
||||||
$cmsDataFields = GridFieldBulkEditingHelper::filterNonEditableRecordsFields($config, $cmsDataFields);
|
$cmsDataFields = GridFieldBulkEditingHelper::filterNonEditableRecordsFields($config, $cmsDataFields);
|
||||||
|
|
||||||
|
// populate fields with record's values -> must some easier way to do this
|
||||||
|
// @TODO: can we handle has_one/has_many/many_many relations
|
||||||
|
if ( $recordID != null )
|
||||||
|
{
|
||||||
|
$record = DataObject::get_by_id($modelClass, $recordID);
|
||||||
|
foreach ( $cmsDataFields as $name => $f )
|
||||||
|
{
|
||||||
|
$cmsDataFields[$name]->setValue( $record->getField($name) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $cmsDataFields;
|
return $cmsDataFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,6 +118,19 @@ class GridFieldBulkEditingHelper {
|
|||||||
return $fieldsHTML;
|
return $fieldsHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function escapeFormFieldsName ( $formFields, $unique )
|
||||||
|
{
|
||||||
|
$prefix = 'record_'.$unique.'_';
|
||||||
|
|
||||||
|
foreach ( $formFields as $name => $f )
|
||||||
|
{
|
||||||
|
$f->Name = $prefix . $f->Name;
|
||||||
|
$formFields[$name] = $f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $formFields;
|
||||||
|
}
|
||||||
|
|
||||||
public static function escapeFormFieldsHTML ( $formFieldsHTML, $unique )
|
public static function escapeFormFieldsHTML ( $formFieldsHTML, $unique )
|
||||||
{
|
{
|
||||||
$prefix = 'record_'.$unique.'_';
|
$prefix = 'record_'.$unique.'_';
|
||||||
|
Loading…
Reference in New Issue
Block a user