You are here

ViewsIsotopeViewsPluginStyleIsotopeSorter.inc in Brainstorm profile 7

Define the "sorter" views plugin.

File

modules/custom/views_isotope/views/ViewsIsotopeViewsPluginStyleIsotopeSorter.inc
View source
<?php

/**
 * @file
 * Define the "sorter" views plugin.
 */

/**
 * Style plugin.
 */
class ViewsIsotopeViewsPluginStyleIsotopeSorter extends views_plugin_style_list {

  /**
   * Set default options.
   */
  public function optionDefinition() {
    $options = parent::optionDefinition();
    $options['instance_id'] = [
      'default' => '',
    ];
    $options['data_fields'] = [
      'default' => [],
    ];
    $options['original'] = [
      'default' => [],
    ];
    return $options;
  }

  /**
   * Render the given style.
   */
  public function optionsForm(&$form, &$form_state) {
    $handlers = $this->display->handler
      ->get_handlers('field');
    if (empty($handlers)) {
      $form['error_markup'] = [
        '#markup' => t('<div class="error messages">You need at least one field before you can configure your isotope settings</div>'),
      ];
      return;
    }
    $field_names = $this->display->handler
      ->get_field_labels();
    $form['data_fields'] = [
      '#type' => 'checkboxes',
      '#options' => $field_names,
      '#required' => TRUE,
      '#title' => t('Data Fields'),
      '#default_value' => $this->options['data_fields'],
      '#description' => t('Select which fields contain data to be used for sorting.'),
    ];
    $form['instance_id'] = [
      '#type' => 'textfield',
      '#title' => t('Enter an Instance ID'),
      '#default_value' => $this->options['instance_id'],
      '#description' => t('(Optional) If you have multiple grids on a page and you want sorts that target specific ones.'),
    ];
    $form['original'] = [
      '#type' => 'textfield',
      '#title' => t('Label for Original Sort option'),
      '#default_value' => !empty($this->options['instance_id']) ? $this->options['instance_id'] : 'Original',
      '#description' => t('Leave blank for no original sort option'),
    ];
  }

}

Classes