diff --git handlers/views_handler_field.inc handlers/views_handler_field.inc index 86b4c1d..7bb887e 100644 --- handlers/views_handler_field.inc +++ handlers/views_handler_field.inc @@ -17,6 +17,7 @@ * 'field' => fieldname); as many fields as are necessary * may be in this array. * - click sortable: If TRUE, this field may be click sorted. + * - no semantic: If TRUE, it disables the semantic output. */ class views_handler_field extends views_handler { var $field_alias = 'unknown'; @@ -145,6 +146,9 @@ class views_handler_field extends views_handler { * Return DIV or SPAN based upon the field's element type. */ function element_type() { + if ($this->options['element type']) { + return $this->options['element type']; + } if (isset($this->definition['element type'])) { return $this->definition['element type']; } @@ -152,6 +156,28 @@ class views_handler_field extends views_handler { return 'span'; } + /** + * Return the class of the field. + */ + function classes($values) { + $classes = $this->options['class']; + if (strpos($this->options['class'], '[') !== FALSE) { + $fake_item = array( + 'alter_text' => TRUE, + 'text' => $this->options['class'], + 'values' => $values, + ); + $tokens = $this->get_render_tokens($fake_item); + foreach ($values as $field_alias => $value) { + if (isset($tokens['[' . $field_alias . ']'])) { + $tokens['[' . $field_alias . ']'] = $value; + } + } + $classes = $this->render_altered($fake_item, $tokens); + } + return $classes; + } + function option_definition() { $options = parent::option_definition(); @@ -177,6 +203,8 @@ class views_handler_field extends views_handler { 'html' => array('default' => FALSE), ), ); + $options['class'] = array('default' => ''); + $options['element type'] = array('default' => ''); $options['empty'] = array('default' => '', 'translatable' => TRUE); $options['hide_empty'] = array('default' => FALSE); $options['empty_zero'] = array('default' => FALSE); @@ -203,6 +231,23 @@ class views_handler_field extends views_handler { '#default_value' => $this->options['exclude'], '#description' => t('Check this box to not display this field, but still load it in the view. Use this option to not show a grouping field in each record, or when doing advanced theming.'), ); + $form['element type'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#title' => t('Element'), + '#type' => 'textfield', + '#size' => '10', + '#default_value' => $this->options['element type'], + ); + $form['class'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#title' => t('Class attributes'), + '#description' => t('You may enter data from this view as per the "Replacement patterns" used in "Rewrite the output of this field".'), + '#type' => 'textfield', + '#size' => '30', + '#default_value' => $this->options['class'], + ); if ($this->allow_advanced_render()) { $form['alter']['#tree'] = TRUE; diff --git theme/theme.inc theme/theme.inc index 50246e9..5cc12cf 100644 --- theme/theme.inc +++ theme/theme.inc @@ -173,9 +173,10 @@ function template_preprocess_views_view_fields(&$vars) { $inline = $object->inline; $object->handler = &$view->field[$id]; - $object->element_type = $object->handler->element_type(); + $object->element_type = check_plain($object->handler->element_type()); $object->class = views_css_safe($id); + $object->classes = views_css_safe($object->handler->classes($vars['row'])); $object->label = check_plain($view->field[$id]->label()); $vars['fields'][$id] = $object; } @@ -346,6 +347,11 @@ function template_preprocess_views_view_table(&$vars) { // Render each field into its appropriate column. foreach ($result as $num => $row) { + // Add semantic classes + if ($classes = $fields[$field]->classes($row)) { + $vars['semantic_classes'][$field][$num] = views_css_safe($classes); + } + if (!empty($fields[$field]) && empty($fields[$field]->options['exclude'])) { $field_output = $renders[$num][$field]; diff --git theme/views-view-fields.tpl.php theme/views-view-fields.tpl.php index 056d562..578d1ff 100644 --- theme/views-view-fields.tpl.php +++ theme/views-view-fields.tpl.php @@ -34,6 +34,6 @@ // $field->element_type is either SPAN or DIV depending upon whether or not // the field is a 'block' element type or 'inline' element type. ?> - <element_type; ?> class="field-content">content; ?>element_type; ?>> + <element_type; ?> class="field-content classes;?>">content; ?>element_type; ?>> inline_html;?>> diff --git theme/views-view-table.tpl.php theme/views-view-table.tpl.php index 8a622b7..2c35621 100644 --- theme/views-view-table.tpl.php +++ theme/views-view-table.tpl.php @@ -32,7 +32,7 @@ $row): ?> $content): ?> - +