function slickgrid_views_plugin::sanitize_columns in Slickgrid 6
Same name and namespace in other branches
- 7.2 includes/slickgrid_views_plugin.inc \slickgrid_views_plugin::sanitize_columns()
- 7 includes/slickgrid_views_plugin.inc \slickgrid_views_plugin::sanitize_columns()
Normalize a list of columns based upon the fields that are available. This compares the fields stored in the style handler to the list of fields actually in the view, removing fields that have been removed and adding new fields in their own column.
- Each field must be in a column.
- Each column must be based upon a field, and that field
is somewhere in the column.
- Any fields not currently represented must be added.
- Columns must be re-ordered to match the fields.
Parameters
$columns: An array of all fields; the key is the id of the field and the value is the id of the column the field should be in.
$fields: The fields to use for the columns. If not provided, they will be requested from the current display. The running render should send the fields through, as they may be different than what the display has listed due to access control or other changes.
1 call to slickgrid_views_plugin::sanitize_columns()
- slickgrid_views_plugin::options_form in ./
slickgrid_views_plugin.inc - Add settings for the particular slickgrid.
File
- ./
slickgrid_views_plugin.inc, line 87
Class
- slickgrid_views_plugin
- Extending the view_plugin_style class to provide a slickgrid style.
Code
function sanitize_columns($columns, $fields = NULL) {
$sanitized = array();
if ($fields === NULL) {
$fields = $this->display->handler
->get_option('fields');
}
// Preconfigure the sanitized array so that the order is retained.
foreach ($fields as $field => $info) {
// Set to itself so that if it isn't touched, it gets column
// status automatically.
$sanitized[$field] = $field;
}
if (is_array($columns)) {
foreach ($columns as $field => $column) {
// first, make sure the field still exists.
if (!isset($sanitized[$field])) {
continue;
}
$column_name = key($column);
// If the field is the column, mark it so, or the column
// it's set to is a column, that's ok
if ($field == $column_name || $columns[$column_name] == $column && !empty($sanitized[$column_name])) {
$sanitized[$field] = $column;
}
// Since we set the field to itself initially, ignoring
// the condition is ok; the field will get its column
// status back.
}
}
return $sanitized;
}