function views_plugin_style_table::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
array $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.
array $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.
Return value
array An array of all the sanitized columns.
1 call to views_plugin_style_table::sanitize_columns()
- views_plugin_style_table::options_form in plugins/
views_plugin_style_table.inc - Render the given style.
File
-
plugins/
views_plugin_style_table.inc, line 132
Class
- views_plugin_style_table
- Style plugin to render each item as a row in a table.
Code
public 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;
}
foreach ($columns as $field => $column) {
// first, make sure the field still exists.
if (!isset($sanitized[$field])) {
continue;
}
// 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 || $columns[$column] == $column && !empty($sanitized[$column])) {
$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;
}