mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
API: Finish up EditingTools Functions
edit fn that returns and filters cms fields
This commit is contained in:
parent
205ec30778
commit
bed1372a45
@ -4,21 +4,82 @@
|
|||||||
* contains common functions
|
* contains common functions
|
||||||
*
|
*
|
||||||
* @author colymba
|
* @author colymba
|
||||||
|
* @package GridFieldBulkEditingTools
|
||||||
*/
|
*/
|
||||||
class GridFieldBulkEditingTools {
|
class GridFieldBulkEditingTools {
|
||||||
//put your code here
|
//put your code here
|
||||||
|
|
||||||
public static function getModelDataFields ( $modelClass )
|
public static function getModelCMSDataFields ( $config, $modelClass )
|
||||||
{
|
{
|
||||||
$cmsFields = singleton($modelClass)->getCMSFields();
|
$cmsFields = singleton($modelClass)->getCMSFields();
|
||||||
$fields = $cmsFields->dataFields();
|
$cmsDataFields = $cmsFields->dataFields();
|
||||||
|
$cmsDataFields = GridFieldBulkEditingTools::filterNonEditableRecordsFields($config, $cmsDataFields);
|
||||||
return $fields->dataFields();
|
|
||||||
|
return $cmsDataFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function filterNonEditableRecordsFields ( $config, $dataFields )
|
||||||
|
{
|
||||||
|
if ( isset($config['editableFields']) )
|
||||||
|
{
|
||||||
|
if ( $config['editableFields'] != null )
|
||||||
|
{
|
||||||
|
foreach ($dataFields as $name => $field)
|
||||||
|
{
|
||||||
|
if ( !in_array($name, $config['editableFields']) )
|
||||||
|
{
|
||||||
|
unset( $dataFields[$name] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $dataFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters out all unwanted fields from the config settings
|
||||||
|
*
|
||||||
|
* @param array $config
|
||||||
|
* @param array $dataFields
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public static function getModelFilteredDataFields ( $config, $dataFields )
|
public static function getModelFilteredDataFields ( $config, $dataFields )
|
||||||
{
|
{
|
||||||
//@todo
|
//remove the image field - for bulk image upload
|
||||||
|
if ( isset($config['imageFieldName']) )
|
||||||
|
{
|
||||||
|
if ( $config['imageFieldName'] != null )
|
||||||
|
{
|
||||||
|
//@TODO: this wont work if the fieldname has ID in it: i.e. TheIDImageID -> remove last 2 char only
|
||||||
|
unset( $dataFields[str_ireplace('ID', '', $config['imageFieldName']) ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//if class blacklist filter
|
||||||
|
if ( count($config['fieldsClassBlacklist']) > 0 )
|
||||||
|
{
|
||||||
|
foreach ($dataFields as $fieldName => $field)
|
||||||
|
{
|
||||||
|
//@TODO find PHP function that return the classname
|
||||||
|
if ( in_array($field->ClassName, $config['fieldsClassBlacklist']) )
|
||||||
|
{
|
||||||
|
array_push($config['fieldsNameBlacklist'], $fieldName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//if name blacklist filter
|
||||||
|
if ( count($config['fieldsNameBlacklist']) > 0 )
|
||||||
|
{
|
||||||
|
foreach ( $config['fieldsNameBlacklist'] as $badFieldName )
|
||||||
|
{
|
||||||
|
unset( $dataFields[ $badFieldName ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $dataFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function filterDatafieldsByClass ( $config, $dataFields )
|
public static function filterDatafieldsByClass ( $config, $dataFields )
|
||||||
@ -33,12 +94,29 @@ class GridFieldBulkEditingTools {
|
|||||||
|
|
||||||
public static function dataFieldsToHTML ( $dataFields )
|
public static function dataFieldsToHTML ( $dataFields )
|
||||||
{
|
{
|
||||||
//@todo
|
$fieldsHTML = array();
|
||||||
|
|
||||||
|
foreach ( $dataFields as $key => $field )
|
||||||
|
{
|
||||||
|
//@TODO: FieldHolder() does not seem to exist on UploadField
|
||||||
|
$fieldsHTML[$key] = $field->FieldHolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fieldsHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function escapeFormFieldsHTML ( $formFieldsHTML )
|
public static function escapeFormFieldsHTML ( $formFieldsHTML, $unique )
|
||||||
{
|
{
|
||||||
//@todo
|
$prefix = 'record_'.$unique.'_';
|
||||||
|
|
||||||
|
foreach ( $formFieldsHTML as $name => $html )
|
||||||
|
{
|
||||||
|
$formFieldsHTML[$name] = str_ireplace ( array('id="', 'for="', 'name="'),
|
||||||
|
array('id="'.$prefix, 'for="'.$prefix, 'name="'.$prefix),
|
||||||
|
$html);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $formFieldsHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function unescapeFormFieldsPOSTData ( $requestVars )
|
public static function unescapeFormFieldsPOSTData ( $requestVars )
|
||||||
|
Loading…
Reference in New Issue
Block a user