class slickgrid_views_plugin in Slickgrid 7
Same name and namespace in other branches
- 6 slickgrid_views_plugin.inc \slickgrid_views_plugin
- 7.2 includes/slickgrid_views_plugin.inc \slickgrid_views_plugin
Extending the view_plugin_style class to provide a slickgrid style.
Hierarchy
- class \views_object
- class \views_plugin
- class \views_plugin_style
- class \slickgrid_views_plugin
- class \views_plugin_style
- class \views_plugin
Expanded class hierarchy of slickgrid_views_plugin
1 string reference to 'slickgrid_views_plugin'
- slickgrid_views_plugins in includes/
slickgrid.views.inc - Implementation of hook_views_plugins()
File
- includes/
slickgrid_views_plugin.inc, line 6
View source
class slickgrid_views_plugin extends views_plugin_style {
var $locked_fields = array();
function init(&$view, &$display, $options = NULL) {
parent::init($view, $display, $options);
if (isset($options['pager']) && $options['pager']) {
// If using slickgrid pager, need to set items per page to 0 so all items are available
$this->display->handler->default_display->options['pager']['options']['items_per_page'] = 0;
}
}
/**
* Set default options
*/
function option_definition() {
$options = parent::option_definition();
// Grouping
$options['grouping_field'] = array(
'default' => NULL,
);
$options['collapse_groups_by_default'] = array(
'default' => FALSE,
);
// Settings
$options['collapsible_taxonomy_field'] = array(
'default' => NULL,
);
// maps to slickgrid option enableColumnResize
$options['enableColumnResize'] = array(
'default' => TRUE,
);
// maps to slickgrid option enableColumnReorder
$options['enableColumnReorder'] = array(
'default' => TRUE,
);
$options['select_columns'] = array(
'default' => TRUE,
);
// maps to slickgrid option asyncEditorLoading
$options['asyncEditorLoading'] = array(
'default' => TRUE,
);
// maps to slickgrid option forceFitColumns
$options['forceFitColumns'] = array(
'default' => false,
);
$options['pager'] = array(
'default' => false,
);
// maps to slickgrid option headerHeight
$options['headerHeight'] = array(
'default' => 42,
);
$options['viewport_height'] = array(
'default' => 500,
);
// maps to slickgrid option rowHeight
$options['rowHeight'] = array(
'default' => 30,
);
// Editing
$options['row_selection_checkbox'] = array(
'default' => false,
);
// If row selection checkbox is enabled, the following values are available
$options['multi_edit'] = array(
'default' => false,
);
$options['delete'] = array(
'default' => false,
);
$options['clone'] = array(
'default' => false,
);
$options['export_selected_rows'] = array(
'default' => false,
);
// Undo editing
$options['undo'] = array(
'default' => false,
);
// Node add button
$options['add'] = array(
'default' => false,
);
// maps to slickgrid option autoEdit
$options['autoEdit'] = array(
'default' => FALSE,
);
return $options;
}
/**
* 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.
*
* @param $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.
* @param $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.
*/
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;
}
/**
* Add settings for the particular slickgrid.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['#attached']['js'] = array(
drupal_get_path('module', 'slickgrid') . '/js/slickgrid.admin.js',
);
$handlers = $this->display->handler
->get_handlers('field');
if (!isset($this->options['columns'])) {
$this->options['columns'] = array();
}
$columns = $this
->sanitize_columns($this->options['columns']);
$field_labels = $this->display->handler
->get_field_labels();
if (empty($columns)) {
$form['error_markup'] = array(
'#value' => t('You need at least one field before you can configure your slickgrid settings'),
'#prefix' => '<div class="error form-item description">',
'#suffix' => '</div>',
);
return;
}
$tabs = array(
'' => '<none>',
);
if (isset($this->options['tabs'])) {
foreach (explode(PHP_EOL, $this->options['tabs']) as $tab) {
$tab = trim($tab);
$tabs[$tab] = $tab;
}
}
// Create an array of fields and form items for setting width, sortable & available plugins
foreach ($columns as $field_id => $column) {
if ($handlers[$field_id]->options['exclude']) {
continue;
}
// Field name
$form['columns'][$field_id]['name'] = array(
'#markup' => $field_labels[$field_id],
);
// Tabs
$form['columns'][$field_id]['tab'] = array(
'#type' => 'select',
'#default_value' => isset($this->options['columns'][$field_id]['tab']) ? $this->options['columns'][$field_id]['tab'] : '',
'#options' => $tabs,
);
// Field for setting a column's width
$form['columns'][$field_id]['width'] = array(
'#type' => 'textfield',
'#default_value' => isset($this->options['columns'][$field_id]['width']) ? $this->options['columns'][$field_id]['width'] : 100,
'#size' => 10,
'#maxlength' => 10,
);
// Can this field be sorted?
if ($handlers[$field_id]
->click_sortable()) {
// Field for setting if a column is sortable
$form['columns'][$field_id]['sortable'] = array(
'#type' => 'checkbox',
'#default_value' => isset($this->options['columns'][$field_id]['sortable']) ? $this->options['columns'][$field_id]['sortable'] : false,
'#size' => 10,
);
}
foreach (slickgrid_get_plugin_types() as $plugin_type => $plugin_label) {
// Only allow editing (and therefore validation) if this is an editable field
if (($plugin_type == 'editor' || $plugin_type == 'validator') & !$this
->field_is_editable($field_id)) {
// Field locked so do not try and find an editor
// Add HTML warning & continue() to next to plugin type
$form['columns'][$field_id][$plugin_type] = array(
'#markup' => t('This field cannot be edited.'),
);
continue;
}
if (count($plugin_options = slickgrid_get_plugin_options_for_field($plugin_type, isset($handlers[$field_id]->options['type']) ? $handlers[$field_id]->options['type'] : null))) {
$form['columns'][$field_id][$plugin_type] = array(
'#type' => 'select',
'#default_value' => isset($this->options['columns'][$field_id][$plugin_type]) ? $this->options['columns'][$field_id][$plugin_type] : '',
'#options' => $plugin_options,
'#attributes' => array(
'class' => array(
$plugin_type,
),
),
);
}
else {
$form['columns'][$field_id][$plugin_type] = array(
'#markup' => t('No %plugin_label plugins for this field.', array(
'%plugin_label' => strtolower($plugin_label),
)),
);
}
}
}
// Grouping field
if ($this
->uses_fields()) {
$options = array(
'' => t('<None>'),
);
$options += $this->display->handler
->get_field_labels();
// If there are no fields, we can't group on them.
if (count($options) > 1) {
$form['grouping'] = array(
'#type' => 'fieldset',
'#title' => t('Grouping'),
);
$form['grouping']['grouping_field'] = array(
'#type' => 'select',
'#title' => t('Grouping field'),
'#options' => $options,
'#default_value' => $this->options['grouping_field'],
'#description' => t('You may optionally specify a field by which to group the records. Leave blank to not group.'),
'#parents' => array(
'style_options',
'grouping_field',
),
);
$form['grouping']['collapse_groups_by_default'] = array(
'#type' => 'checkbox',
'#title' => t('Collapse groups by default'),
'#description' => t('All groups should be collapsed by default.'),
'#default_value' => $this->options['collapse_groups_by_default'],
'#states' => array(
'invisible' => array(
'#edit-style-options-grouping-field' => array(
'value' => '',
),
),
),
'#parents' => array(
'style_options',
'collapse_groups_by_default',
),
);
}
}
// Tabs
$form['tab_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Tabs'),
);
$form['tab_settings']['tabs'] = array(
'#type' => 'textarea',
'#title' => t('Tab names'),
'#default_value' => isset($this->options['tabs']) ? $this->options['tabs'] : '',
'#parents' => array(
'style_options',
'tabs',
),
);
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Settings'),
);
$form['settings']['enableColumnResize'] = array(
'#type' => 'checkbox',
'#title' => t('Enable resizing columns'),
'#default_value' => $this->options['enableColumnResize'],
'#parents' => array(
'style_options',
'enableColumnResize',
),
);
$form['settings']['enableColumnReorder'] = array(
'#type' => 'checkbox',
'#title' => t('Enable reordering columns'),
'#default_value' => $this->options['enableColumnReorder'],
'#parents' => array(
'style_options',
'enableColumnReorder',
),
);
$form['settings']['select_columns'] = array(
'#type' => 'checkbox',
'#title' => t('Column visibility'),
'#description' => t('Allow users to show & hide columns'),
'#default_value' => $this->options['select_columns'],
'#parents' => array(
'style_options',
'select_columns',
),
);
$form['settings']['asyncEditorLoading'] = array(
'#type' => 'checkbox',
'#title' => t('A sync editor loading'),
'#default_value' => $this->options['asyncEditorLoading'],
'#parents' => array(
'style_options',
'asyncEditorLoading',
),
);
$form['settings']['forceFitColumns'] = array(
'#type' => 'checkbox',
'#title' => t('Force fit columns'),
'#default_value' => $this->options['forceFitColumns'],
'#description' => t('Force column widths to fit the grid.'),
'#parents' => array(
'style_options',
'forceFitColumns',
),
);
$form['settings']['pager'] = array(
'#type' => 'checkbox',
'#title' => t('Override paging'),
'#default_value' => $this->options['pager'],
'#description' => t('If selected, use slickgrid\'s in-built pagination instead of views\'.'),
'#parents' => array(
'style_options',
'pager',
),
);
$form['settings']['headerHeight'] = array(
'#title' => t('Header height'),
'#type' => 'textfield',
'#default_value' => $this->options['headerHeight'],
'#size' => 10,
'#maxlength' => 10,
'#parents' => array(
'style_options',
'headerHeight',
),
);
$form['settings']['viewport_height'] = array(
'#title' => t('Viewport height'),
'#type' => 'textfield',
'#default_value' => $this->options['viewport_height'],
'#size' => 10,
'#maxlength' => 10,
'#parents' => array(
'style_options',
'viewport_height',
),
);
$form['settings']['rowHeight'] = array(
'#title' => t('Row height'),
'#type' => 'textfield',
'#default_value' => $this->options['rowHeight'],
'#size' => 10,
'#maxlength' => 10,
'#parents' => array(
'style_options',
'rowHeight',
),
);
$form['editing'] = array(
'#type' => 'fieldset',
'#title' => t('Editing'),
);
foreach ($columns as $field_id => $column) {
$form['editing']['#states']['invisible']['#edit-style-options-columns-' . drupal_html_id($field_id) . '-editors'] = array(
'value' => '',
);
}
$form['editing']['row_selection_checkbox'] = array(
'#type' => 'checkbox',
'#title' => t('Row selection checkbox'),
'#description' => t('Add a row selection checkbox.'),
'#default_value' => $this->options['row_selection_checkbox'],
'#parents' => array(
'style_options',
'row_selection_checkbox',
),
);
$form['editing']['multi_edit'] = array(
'#type' => 'checkbox',
'#title' => t('Multi-edit'),
'#description' => t('Users can select & edit multiple items at once.'),
'#default_value' => $this->options['multi_edit'],
'#parents' => array(
'style_options',
'multi_edit',
),
'#prefix' => '<div style="padding-left: 30px">',
'#states' => array(
'invisible' => array(
'input[name="style_options[row_selection_checkbox]"]' => array(
'checked' => FALSE,
),
),
),
);
$form['editing']['delete'] = array(
'#title' => t('Delete items'),
'#description' => t('Allow users to delete items from within the slickgrid.'),
'#type' => 'checkbox',
'#default_value' => $this->options['delete'],
'#parents' => array(
'style_options',
'delete',
),
'#states' => array(
'invisible' => array(
'input[name="style_options[row_selection_checkbox]"]' => array(
'checked' => FALSE,
),
),
),
);
$form['editing']['clone'] = array(
'#title' => t('Clone items'),
'#description' => t('Allow users to clone items from within the slickgrid.'),
'#type' => 'checkbox',
'#default_value' => $this->options['clone'],
'#parents' => array(
'style_options',
'clone',
),
'#states' => array(
'invisible' => array(
'input[name="style_options[row_selection_checkbox]"]' => array(
'checked' => FALSE,
),
),
),
);
$form['editing']['export_selected_rows'] = array(
'#title' => t('Export selected rows'),
'#description' => t('Allow users to select rows to export (requires views data export).'),
'#type' => 'checkbox',
'#default_value' => $this->options['export_selected_rows'],
'#parents' => array(
'style_options',
'export_selected_rows',
),
'#suffix' => '</div>',
'#states' => array(
'invisible' => array(
'input[name="style_options[row_selection_checkbox]"]' => array(
'checked' => FALSE,
),
),
),
);
$form['editing']['Add'] = array(
'#type' => 'select',
'#title' => t('Add'),
'#options' => array_merge(array(
'<none>',
), $this
->list_addable_entities()),
'#description' => t('Allow users to add an entity from within slickgrid.'),
'#default_value' => $this->options['add'],
'#parents' => array(
'style_options',
'add',
),
);
$form['editing']['undo'] = array(
'#type' => 'checkbox',
'#title' => t('Undo'),
'#default_value' => $this->options['undo'],
'#parents' => array(
'style_options',
'undo',
),
);
// Only allow undo for nodes
if ($this->view->base_table == 'node') {
$form['editing']['undo']['#description'] = t('Allow users to undo updates. Warning: if turned on, all updates will create a node revision.');
}
else {
$form['editing']['undo']['#disabled'] = true;
$form['editing']['undo']['#description'] = t('Versioning is required for undo so this feature is only available for nodes.');
$form['editing']['undo']['#value'] = false;
}
$form['editing']['autoEdit'] = array(
'#type' => 'checkbox',
'#title' => t('Auto edit'),
'#default_value' => $this->options['autoEdit'],
'#description' => t('Activate edit on entry to cell, otherwise double click to edit.'),
'#parents' => array(
'style_options',
'autoEdit',
),
);
$form['#theme'] = 'slickgrid_views_plugin_table';
}
function field_is_editable($field_name) {
if (!count($this->locked_fields)) {
$this->locked_fields = slickgrid_get_entity_keys();
}
// Field is only editable if it's not a locked field (an entity key field)
return !in_array($field_name, $this->locked_fields);
}
function list_addable_entities() {
$entities = array();
foreach ($entities_info = entity_get_info() as $entity_type => $entity_info) {
foreach ($entity_info['bundles'] as $bundle_name => $bundle) {
if (isset($bundle['add']) && $bundle['add']) {
$entities[$entity_type . '/' . $bundle_name] = $entity_info['label'] . ': ' . $bundle['label'];
}
}
}
return $entities;
}
function query() {
// We always want the query to be distinct - this also adds the correct base field
$this->view->query
->set_distinct();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
slickgrid_views_plugin:: |
property | |||
slickgrid_views_plugin:: |
function | |||
slickgrid_views_plugin:: |
function |
Initialize a style plugin. Overrides views_plugin_style:: |
||
slickgrid_views_plugin:: |
function | |||
slickgrid_views_plugin:: |
function |
Add settings for the particular slickgrid. Overrides views_plugin_style:: |
||
slickgrid_views_plugin:: |
function |
Set default options Overrides views_plugin_style:: |
||
slickgrid_views_plugin:: |
function |
Add anything to the query that we might need to. Overrides views_plugin_style:: |
||
slickgrid_views_plugin:: |
function | 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. | ||
views_object:: |
public | property | Handler's definition. | |
views_object:: |
public | property | Except for displays, options for the object will be held here. | 1 |
views_object:: |
function | Collect this handler's option definition and alter them, ready for use. | ||
views_object:: |
public | function | Views handlers use a special construct function. | 4 |
views_object:: |
public | function | 1 | |
views_object:: |
public | function | ||
views_object:: |
public | function | Always exports the option, regardless of the default value. | |
views_object:: |
public | function | Set default options on this object. | 1 |
views_object:: |
public | function | Set default options. | |
views_object:: |
public | function | Let the handler know what its full definition is. | |
views_object:: |
public | function | Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away. | |
views_object:: |
public | function | Unpack a single option definition. | |
views_object:: |
public | function | Unpacks each handler to store translatable texts. | |
views_object:: |
public | function | ||
views_plugin:: |
public | property | The current used views display. | |
views_plugin:: |
public | property | The plugin name of this plugin, for example table or full. | |
views_plugin:: |
public | property | The plugin type of this plugin, for example style or query. | |
views_plugin:: |
public | property |
The top object of a view. Overrides views_object:: |
1 |
views_plugin:: |
public | function | Provide a list of additional theme functions for the theme info page. | |
views_plugin:: |
public | function | Handle any special handling on the validate form. | 9 |
views_plugin:: |
public | function | Return the human readable name of the display. | |
views_plugin:: |
public | function | Returns the summary of the settings in the display. | 8 |
views_plugin:: |
public | function | Provide a full list of possible theme templates used by this style. | |
views_plugin_style:: |
public | property | The row plugin, if it's initialized and the style itself supports it. | |
views_plugin_style:: |
public | property | Store all available tokens row rows. | |
views_plugin_style:: |
public | function | Called by the view builder to see if this style handler wants to interfere with the sorts. If so it should build; if it returns any non-TRUE value, normal sorting will NOT be added to the query. | 1 |
views_plugin_style:: |
public | function | Called by the view builder to let the style build a second set of sorts that will come after any other sorts in the view. | 1 |
views_plugin_style:: |
public | function |
Destructor. Overrides views_object:: |
|
views_plugin_style:: |
public | function | Should the output of the style plugin be rendered even if it's empty. | 1 |
views_plugin_style:: |
public | function | Get a rendered field. | |
views_plugin_style:: |
public | function | Get the raw field value. | |
views_plugin_style:: |
public | function | Return the token replaced row class for the specified row. | |
views_plugin_style:: |
public | function |
Validate the options form. Overrides views_plugin:: |
|
views_plugin_style:: |
public | function | Allow the style to do stuff before each row is rendered. | |
views_plugin_style:: |
public | function | Render the display in this style. | 5 |
views_plugin_style:: |
public | function | Render all of the fields for a given style and store them on the object. | |
views_plugin_style:: |
public | function | Group records as needed for rendering. | |
views_plugin_style:: |
public | function | Render the grouping sets. | |
views_plugin_style:: |
public | function | Take a value and apply token replacement logic to it. | |
views_plugin_style:: |
public | function | Return TRUE if this style also uses fields. | |
views_plugin_style:: |
public | function | Return TRUE if this style also uses a row plugin. | |
views_plugin_style:: |
public | function | Return TRUE if this style also uses a row plugin. | |
views_plugin_style:: |
public | function | Return TRUE if this style uses tokens. | |
views_plugin_style:: |
public | function |
Validate that the plugin is correct and can be saved. Overrides views_plugin:: |