You are here

views_table_highlighter.module in Views Table Highlighter 7

Same filename and directory in other branches
  1. 6 views_table_highlighter.module

File

views_table_highlighter.module
View source
<?php

/**
 * Implements hook_init().
 */
function views_table_highlighter_init() {
  drupal_add_css(drupal_get_path('module', 'views_table_highlighter') . '/views_table_highlighter.css');
}

/**
 * Implements hook_views_api().
 */
function views_table_highlighter_views_api() {
  return array(
    'api' => 3.0,
  );
}

/**
 * Simplifies field values, so their data can be uniformly accessed.
 */
function _views_table_highlighter_cook_fields(array $fields) {
  unset($fields['_field_data']);
  foreach ($fields as $key => $value) {
    if (is_array($value)) {
      if (isset($value[0]['raw']['value'])) {
        $fields[$key] = $value[0]['raw']['value'];
      }
      else {
        $fields[$key] = '';
      }
    }
  }
  return $fields;
}

/**
 * Implements hook_preprocess().
 */
function views_table_highlighter_preprocess(&$variables, $hook) {
  if ($hook === 'views_view_table' && isset($variables['view']->style_plugin->options['views_table_highlighter'])) {
    foreach ($variables['view']->result as $i => $fieldset) {
      $GLOBALS['views_table_highlighter_fieldset'] = _views_table_highlighter_cook_fields((array) $fieldset);
      $color = php_eval('<?php extract($GLOBALS["views_table_highlighter_fieldset"]); ' . $variables['view']->style_options['views_table_highlighter']['code']);
      if ($color) {
        $variables['row_classes'][$i][] = "views-table-highlighter-{$color}";
      }
    }
  }
}

Functions

Namesort descending Description
views_table_highlighter_init Implements hook_init().
views_table_highlighter_preprocess Implements hook_preprocess().
views_table_highlighter_views_api Implements hook_views_api().
_views_table_highlighter_cook_fields Simplifies field values, so their data can be uniformly accessed.