views_table_highlighter_plugin_style.inc in Views Table Highlighter 6
Same filename and directory in other branches
Implements a Views Style for Views Table Highlighter, derived from the Views Table style.
File
views_table_highlighter_plugin_style.incView source
<?php
/**
* @file
* Implements a Views Style for Views Table Highlighter, derived from the Views Table style.
*/
class views_table_highlighter_plugin_style extends views_plugin_style_table {
function options_form(&$form, &$form_values) {
parent::options_form($form, $form_values);
$vth_options = $this->options['views_table_highlighter'];
// prepare some sample values for our form, by executing the current view.
$example_view = $this->view
->copy();
if ($this->view->current_display) {
$example_view
->set_display($this->view->current_display);
}
else {
$example_view
->init_display();
}
$example_view
->pre_execute();
$example_view
->execute();
$fieldtext = '';
$fields = (array) $example_view->result[0];
ksort($fields);
foreach ($fields as $field => $value) {
// find first non-null value
foreach ($example_view->result as $result) {
$value = $result->{$field};
if ($value) {
break;
}
}
$fieldtext .= '<li>$' . $field . ' == "' . htmlentities(addslashes($value)) . '"</li>';
}
reset($fields);
$form['views_table_highlighter'] = array(
'#type' => 'fieldset',
'#title' => t('Table Highlighter'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'code' => array(
'#type' => 'textarea',
'#rows' => 2,
'#title' => t('Highlighter PHP code'),
'#default_value' => $vth_options['code'] ? $vth_options['code'] : 'if ($' . key($fields) . '=="' . htmlentities(current($fields)) . '") return \'red\';',
'#process' => array(
'views_process_dependency',
),
'#description' => "<p>" . t('Enter PHP code that returns the color with which this row should be highlighted. Return without a value to leave this row unlit.') . '</p>' . '<table><tr valign="top"><td>' . t('Available fields:') . '<ul>' . $fieldtext . '</ul>' . t('(Above are sample values from the first few rows of this view.)') . '</td><td>' . t('Available colors:') . "<ul><li>'red'</li><li>'yellow'</li><li>'green'</li><li>'cyan'</li><li>'blue'</li><li>'magenta'</li></ul>" . '</td></tr></table>',
),
);
}
}
Classes
Name | Description |
---|---|
views_table_highlighter_plugin_style | @file Implements a Views Style for Views Table Highlighter, derived from the Views Table style. |