function slickgrid_views_plugin::sanitize_columns in Slickgrid 7
Same name and namespace in other branches
- 6 slickgrid_views_plugin.inc \slickgrid_views_plugin::sanitize_columns()
- 7.2 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 includes/
slickgrid_views_plugin.inc - Add settings for the particular slickgrid.
File
- includes/
slickgrid_views_plugin.inc, line 120
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) {
// Make sure the field still exists.
if (isset($sanitized[$field])) {
$sanitized[$field] = $column;
}
}
}
return $sanitized;
}