You are here

function slickgrid_views_plugin::options_form in Slickgrid 6

Same name and namespace in other branches
  1. 7.2 includes/slickgrid_views_plugin.inc \slickgrid_views_plugin::options_form()
  2. 7 includes/slickgrid_views_plugin.inc \slickgrid_views_plugin::options_form()

Add settings for the particular slickgrid.

File

./slickgrid_views_plugin.inc, line 121

Class

slickgrid_views_plugin
Extending the view_plugin_style class to provide a slickgrid style.

Code

function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);
  $handlers = $this->display->handler
    ->get_handlers('field');
  $columns = $this
    ->sanitize_columns($this->options['columns']);
  $field_names = $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;
  }

  // Array of node term fields that can be selected to be a collapsible taxonomy
  $collapsible_taxonomy_options = array(
    '' => t('<None>'),
  );

  // Create an array of allowed columns from the data we know:
  foreach ($columns as $field => $column) {
    if ($handlers[$field]->options['exclude']) {
      continue;
    }

    // Field for setting a column's width
    $form['columns'][$field]['width'] = array(
      '#type' => 'textfield',
      '#default_value' => $this->options['columns'][$field]['width'] ? $this->options['columns'][$field]['width'] : 100,
      '#size' => 10,
      '#maxlength' => 10,
    );

    // Can this field be sorted?
    if ($handlers[$field]
      ->click_sortable()) {

      // Field for setting if a column is sortable
      $form['columns'][$field]['sortable'] = array(
        '#type' => 'checkbox',
        '#default_value' => $this->options['columns'][$field]['sortable'] ? $this->options['columns'][$field]['sortable'] : false,
        '#size' => 10,
      );
    }
    $filters = array();

    // Is this a CCK field?
    // If it is we know its editable
    if (isset($handlers[$field]->content_field['widget']['type'])) {
      $filters['field_type'] = $handlers[$field]->content_field['widget']['type'];
    }
    else {

      // If it's not a CCK field, make a field_type from {table}_{field}
      // We can then define editors for node fields (eg: node_title) and any other fields
      $filters['field_type'] = $handlers[$field]->table . '_' . $handlers[$field]->real_field;
    }

    // Is this a term node type?
    if ($filters['field_type'] == 'term_node_tid') {

      // If it is, this can be provided as "collapsible taxonomy" option
      $collapsible_taxonomy_options[$field] = $field_names[$field];
    }
    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
        ->is_editable($handlers[$field], $filters['field_type'])) {

        // Field locked so do not try and find an editor
        // Add HTML warning & continue() to next to plugin type
        $form['columns'][$field][$plugin_type] = array(
          '#value' => t('This field cannot be edited.'),
        );
        continue;
      }
      $filters['plugin_type'] = $plugin_type;
      $plugins = slickgrid_get_plugins($filters);

      // Are there plugins we can use for this field?
      if (count($plugins)) {
        $form['columns'][$field][$plugin_type] = array(
          '#type' => 'select',
          '#default_value' => $this->options['columns'][$field][$plugin_type] ? $this->options['columns'][$field][$plugin_type] : '',
          '#options' => $this
            ->get_plugin_options($plugins),
        );
      }
      else {
        $form['columns'][$field][$plugin_type] = array(
          '#value' => t('No %plugin_label plugins for this field.', array(
            '%plugin_label' => strtolower($plugin_label),
          )),
        );
      }
    }

    // Field for setting if a column is editable
    // markup for the field name
    $form['columns'][$field]['name'] = array(
      '#value' => $field_names[$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_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.'),
      );
      $form['collapse_groups_by_default'] = array(
        '#type' => 'checkbox',
        '#title' => t('Collapse groups'),
        '#description' => t('All groups should be collapsed by default.'),
        '#default_value' => $this->options['collapse_groups_by_default'],
      );
    }
    if (count($collapsible_taxonomy_options) > 1) {

      // Default value of <none> so needs to be greater than 1 if there's actually any fields
      $form['collapsible_taxonomy_field'] = array(
        '#type' => 'select',
        '#title' => t('Collapsible taxonomy field'),
        '#options' => $collapsible_taxonomy_options,
        '#default_value' => $this->options['collapsible_taxonomy_field'],
        '#description' => t('You may optionally specify a collapsible taxonomy field. Setting this will add a taxonomy parent relationship & ordering to the view.'),
      );
    }
  }
  $form['enableColumnResize'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable resizing columns'),
    '#default_value' => $this->options['enableColumnResize'],
  );
  $form['enableColumnReorder'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable reordering columns'),
    '#default_value' => $this->options['enableColumnReorder'],
  );
  $form['select_columns'] = array(
    '#type' => 'checkbox',
    '#title' => t('Column visibility'),
    '#description' => t('Allow users to show &amp; hide columns'),
    '#default_value' => $this->options['select_columns'],
  );
  $form['delete_nodes'] = array(
    '#title' => t('Delete nodes'),
    '#description' => t('Allow users to delete nodes from within the slickgrid.'),
    '#type' => 'checkbox',
    '#default_value' => $this->options['delete_nodes'],
  );
  $form['asyncEditorLoading'] = array(
    '#type' => 'checkbox',
    '#title' => t('A sync editor loading'),
    '#default_value' => $this->options['asyncEditorLoading'],
  );
  $form['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.'),
  );
  $form['forceFitColumns'] = array(
    '#type' => 'checkbox',
    '#title' => t('Force fit columns'),
    '#default_value' => $this->options['forceFitColumns'],
    '#description' => t('Force column widths to fit the grid.'),
  );
  $form['multi_edit'] = array(
    '#type' => 'checkbox',
    '#title' => t('Multi-edit'),
    '#description' => t('Users can select & edit multiple nodes at once.'),
    '#default_value' => $this->options['multi_edit'],
  );
  $form['undo'] = array(
    '#type' => 'checkbox',
    '#title' => t('Undo'),
    '#description' => t('Allow users to undo updates. Warning: if turned on, all updates will create a node revision.'),
    '#default_value' => $this->options['undo'],
  );
  $form['viewport_height'] = array(
    '#title' => t('Viewport height'),
    '#type' => 'textfield',
    '#default_value' => $this->options['viewport_height'],
    '#size' => 10,
    '#maxlength' => 10,
  );
  $form['rowHeight'] = array(
    '#title' => t('Row height'),
    '#type' => 'textfield',
    '#default_value' => $this->options['rowHeight'],
    '#size' => 10,
    '#maxlength' => 10,
  );
  $form['#theme'] = 'slickgrid_views_plugin_table';
}