You are here

class semanticviews_plugin_style_default in Semantic Views 7

Same name and namespace in other branches
  1. 6 semanticviews_plugin_style_default.inc \semanticviews_plugin_style_default

Default style plugin to render rows one after another with no decorations.

Hierarchy

Expanded class hierarchy of semanticviews_plugin_style_default

1 string reference to 'semanticviews_plugin_style_default'
semanticviews_views_plugins in ./semanticviews.views.inc
Implements hook_views_plugins().

File

./semanticviews_plugin_style_default.inc, line 12
Contains the default style plugin.

View source
class semanticviews_plugin_style_default extends views_plugin_style {

  /**
   * Set default options
   */
  function options(&$options) {
    parent::options($options);
  }

  /**
   * Set default options
   */
  function option_definition() {
    $options = parent::option_definition();

    // Group option definition.
    $options['group'] = array(
      'contains' => array(
        'element_type' => array(
          'default' => 'h3',
        ),
        'class' => array(
          'default' => 'title',
        ),
      ),
    );

    // List option definition.
    $options['list'] = array(
      'contains' => array(
        'element_type' => array(
          'default' => '',
        ),
        'class' => array(
          'default' => '',
        ),
      ),
    );

    // Row option definition.
    $options['row'] = array(
      'contains' => array(
        'element_type' => array(
          'default' => 'div',
        ),
        'class' => array(
          'default' => '',
        ),
        'first_class' => array(
          'default' => 'first',
        ),
        'last_class' => array(
          'default' => 'last',
        ),
        'last_every_nth' => array(
          'default' => '0',
        ),
        'striping_classes' => array(
          'default' => 'odd even',
        ),
      ),
    );
    return $options;
  }

  /**
   * Render the given style.
   */
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);

    // Group options.
    $form['group'] = array(
      '#type' => 'fieldset',
      '#title' => t('Grouping title'),
      '#description' => t('If using groups, the view will insert the grouping’s title field.'),
      '#attributes' => array(
        'class' => array(
          'clearfix',
        ),
      ),
    );
    $form['group']['element_type'] = array(
      '#prefix' => '<div class="views-left-30">',
      '#suffix' => '</div>',
      '#title' => t('Element'),
      '#type' => 'textfield',
      '#size' => '10',
      '#default_value' => $this->options['group']['element_type'],
    );
    $form['group']['class'] = array(
      '#prefix' => '<div class="views-right-70">',
      '#suffix' => '</div>',
      '#title' => t('Class attribute'),
      '#type' => 'textfield',
      '#size' => '30',
      '#default_value' => $this->options['group']['class'],
    );

    // List options.
    $form['list'] = array(
      '#type' => 'fieldset',
      '#title' => t('List'),
      '#description' => t('If the output should be a HTML list, select the element and class attribute. The row element should also be set to %li.', array(
        '%li' => 'li',
      )),
      '#attributes' => array(
        'class' => array(
          'clearfix',
        ),
      ),
    );
    $form['list']['element_type'] = array(
      '#prefix' => '<div class="views-left-30">',
      '#suffix' => '</div>',
      '#type' => 'radios',
      '#title' => t('List type'),
      '#options' => array(
        '' => t('None'),
        'ul' => t('Unordered list'),
        'ol' => t('Ordered list'),
        'dl' => t('Definition list'),
        'div' => t('Division <div>'),
      ),
      '#default_value' => $this->options['list']['element_type'],
    );
    $form['list']['class'] = array(
      '#prefix' => '<div class="views-right-70">',
      '#suffix' => '</div>',
      '#title' => t('Class attribute'),
      '#type' => 'textfield',
      '#size' => '30',
      '#default_value' => $this->options['list']['class'],
    );

    // Row options.
    $form['row'] = array(
      '#type' => 'fieldset',
      '#title' => t('Row'),
      '#attributes' => array(
        'class' => array(
          'clearfix',
        ),
      ),
    );
    $form['row']['element_type'] = array(
      '#prefix' => '<div class="clearfix"><div class="views-left-30">',
      '#suffix' => '</div>',
      '#title' => t('Element'),
      '#type' => 'textfield',
      '#size' => '10',
      '#default_value' => $this->options['row']['element_type'],
    );
    $form['row']['class'] = array(
      '#prefix' => '<div class="views-right-70">',
      '#suffix' => '</div></div>',
      '#title' => t('Class attribute'),
      '#type' => 'textfield',
      '#size' => '30',
      '#default_value' => $this->options['row']['class'],
      '#description' => t('Insert a %hash where you want row enumeration.', array(
        '%hash' => '#',
      )),
    );

    // First and last class options.
    $form['row']['first_last'] = array(
      '#type' => 'fieldset',
      '#title' => t('First and last classes'),
      // The #parents attribute must be set to avoid another array layer around
      // the group of FIRST/LAST class attribute options.
      '#parents' => array(
        'style_options',
        'row',
      ),
      '#description' => t('If the %last_every_nth option is empty or zero, the %first_class and %last_class are added once to only the first and last rows in the pager set. If this option is greater than 1, these classes are added to every n<sup>th</sup> row, which may be useful for grid layouts where the initial and final unit&rsquo;s lateral margins must be 0.', array(
        '%last_every_nth' => 'FIRST/LAST every nth',
        '%first_class' => 'FIRST class attribute',
        '%last_class' => 'LAST class attribute',
      )),
      '#attributes' => array(
        'class' => array(
          'clearfix',
        ),
      ),
    );
    $form['row']['first_last']['last_every_nth'] = array(
      '#type' => 'textfield',
      '#size' => '10',
      '#title' => t('FIRST/LAST every n<sup>th</sup>'),
      '#default_value' => $this->options['row']['last_every_nth'],
    );
    $form['row']['first_last']['first_class'] = array(
      '#prefix' => '<div class="views-left-50">',
      '#suffix' => '</div>',
      '#title' => t('FIRST class attribute'),
      '#type' => 'textfield',
      '#size' => '30',
      '#default_value' => $this->options['row']['first_class'],
    );
    $form['row']['first_last']['last_class'] = array(
      '#prefix' => '<div class="views-right-50">',
      '#suffix' => '</div>',
      '#title' => t('LAST class attribute'),
      '#type' => 'textfield',
      '#size' => '30',
      '#default_value' => $this->options['row']['last_class'],
    );

    // Striping class options.
    $form['row']['striping_classes'] = array(
      '#title' => t('Striping class attributes'),
      '#type' => 'textfield',
      '#size' => '30',
      '#default_value' => $this->options['row']['striping_classes'],
      '#description' => t('One striping class attribute is applied to each row. Separate multiple attributes with a space.'),
    );

    // Get a list of the available fields for token replacement.
    $options = array();
    foreach ($this->view->display_handler
      ->get_handlers('field') as $field => $handler) {
      $options[t('Fields')]["[{$field}]"] = $handler
        ->ui_name();
    }

    // Default text.
    $output = t('<p>Add additional fields to this display in order to get any available replacement patterns.</p>');

    // We have some options, so make a list.
    if (!empty($options)) {
      $output = t('<p>The following replacement patterns are available for this display. Use the pattern shown on the left to display the value indicated on the right.</p>');
      foreach (array_keys($options) as $type) {
        if (!empty($options[$type])) {
          $items = array();
          foreach ($options[$type] as $key => $value) {
            $items[] = $key . ' == ' . $value;
          }
          $output .= theme('item_list', $items, $type);
        }
      }
    }
    $form['row']['alter'] = array(
      '#type' => 'markup',
      '#value' => '<fieldset id="views-tokens-help"><legend>' . t('Replacement patterns') . '</legend>' . $output . '</fieldset>',
    );
  }

  /**
   * Validate the options form.
   */
  function options_validate(&$form, &$form_state) {
    parent::options_validate($form, $form_state);

    // TODO: validate that the elements and classes are valid HTML. This is not
    // a substitute for output filtering.
  }

  /**
   * Return the token replaced class for the specified row.
   */
  function tokenize_class($row_index, $class) {

    // Replaces the # to the row enumeration.
    $class = strtr($class, array(
      '#' => $row_index,
    ));
    if ($this
      ->uses_fields() && $this->view->field) {
      $class = strip_tags($this
        ->tokenize_value($class, $row_index));
    }
    $classes = explode(' ', $class);
    foreach ($classes as &$class) {
      $class = drupal_clean_css_identifier($class);
    }
    return implode(' ', $classes);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
semanticviews_plugin_style_default::options function Set default options Overrides views_object::options
semanticviews_plugin_style_default::options_form function Render the given style. Overrides views_plugin_style::options_form
semanticviews_plugin_style_default::options_validate function Validate the options form. Overrides views_plugin_style::options_validate
semanticviews_plugin_style_default::option_definition function Set default options Overrides views_plugin_style::option_definition
semanticviews_plugin_style_default::tokenize_class function Return the token replaced class for the specified row.
views_object::$definition public property Handler's definition.
views_object::$options public property Except for displays, options for the object will be held here. 1
views_object::altered_option_definition function Collect this handler's option definition and alter them, ready for use.
views_object::construct public function Views handlers use a special construct function. 4
views_object::export_option public function 1
views_object::export_options public function
views_object::export_option_always public function Always exports the option, regardless of the default value.
views_object::set_default_options public function Set default options.
views_object::set_definition public function Let the handler know what its full definition is.
views_object::unpack_options public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
views_object::unpack_translatable public function Unpack a single option definition.
views_object::unpack_translatables public function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults public function
views_plugin::$display public property The current used views display.
views_plugin::$plugin_name public property The plugin name of this plugin, for example table or full.
views_plugin::$plugin_type public property The plugin type of this plugin, for example style or query.
views_plugin::$view public property The top object of a view. Overrides views_object::$view 1
views_plugin::additional_theme_functions public function Provide a list of additional theme functions for the theme info page.
views_plugin::options_submit public function Handle any special handling on the validate form. 9
views_plugin::plugin_title public function Return the human readable name of the display.
views_plugin::summary_title public function Returns the summary of the settings in the display. 8
views_plugin::theme_functions public function Provide a full list of possible theme templates used by this style.
views_plugin_style::$row_plugin public property The row plugin, if it's initialized and the style itself supports it.
views_plugin_style::$row_tokens public property Store all available tokens row rows.
views_plugin_style::build_sort 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::build_sort_post 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::destroy public function Destructor. Overrides views_object::destroy
views_plugin_style::even_empty public function Should the output of the style plugin be rendered even if it's empty. 1
views_plugin_style::get_field public function Get a rendered field.
views_plugin_style::get_field_value public function Get the raw field value.
views_plugin_style::get_row_class public function Return the token replaced row class for the specified row.
views_plugin_style::init public function Initialize a style plugin.
views_plugin_style::pre_render public function Allow the style to do stuff before each row is rendered.
views_plugin_style::query public function Add anything to the query that we might need to. Overrides views_plugin::query 2
views_plugin_style::render public function Render the display in this style. 5
views_plugin_style::render_fields public function Render all of the fields for a given style and store them on the object.
views_plugin_style::render_grouping public function Group records as needed for rendering.
views_plugin_style::render_grouping_sets public function Render the grouping sets.
views_plugin_style::tokenize_value public function Take a value and apply token replacement logic to it.
views_plugin_style::uses_fields public function Return TRUE if this style also uses fields.
views_plugin_style::uses_row_class public function Return TRUE if this style also uses a row plugin.
views_plugin_style::uses_row_plugin public function Return TRUE if this style also uses a row plugin.
views_plugin_style::uses_tokens public function Return TRUE if this style uses tokens.
views_plugin_style::validate public function Validate that the plugin is correct and can be saved. Overrides views_plugin::validate