From 6fc4c2c8c02d160f8a493e63c9a6e33c3d28aa8e Mon Sep 17 00:00:00 2001 From: Colan Schwartz Date: Fri, 7 Sep 2012 11:39:05 -0400 Subject: [PATCH] Issue #843708 by mgifford, colan: Add caption element to table & grid styles. --- plugins/views_plugin_style_grid.inc | 10 +++++++++- plugins/views_plugin_style_table.inc | 11 ++++++++++- theme/theme.inc | 16 ++++++++++++++++ theme/views-view-grid.tpl.php | 4 ++++ theme/views-view-table.tpl.php | 5 +++-- 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/plugins/views_plugin_style_grid.inc b/plugins/views_plugin_style_grid.inc index 9be7ee1..a2e4375 100644 --- a/plugins/views_plugin_style_grid.inc +++ b/plugins/views_plugin_style_grid.inc @@ -21,6 +21,7 @@ class views_plugin_style_grid extends views_plugin_style { $options['alignment'] = array('default' => 'horizontal'); $options['fill_single_line'] = array('default' => TRUE, 'bool' => TRUE); $options['summary'] = array('default' => ''); + $options['caption'] = array('default' => ''); return $options; } @@ -52,10 +53,17 @@ class views_plugin_style_grid extends views_plugin_style { '#default_value' => !empty($this->options['fill_single_line']), ); + $form['caption'] = array( + '#type' => 'textfield', + '#title' => t('Short description of table'), + '#description' => t('Include a caption for better accessibility of your table.'), + '#default_value' => $this->options['caption'], + ); + $form['summary'] = array( '#type' => 'textfield', '#title' => t('Table summary'), - '#description' => t('This value will be displayed as table-summary attribute in the html. Set this for better accessiblity of your site.'), + '#description' => t('This value will be displayed as table-summary attribute in the html. Use this to give a summary of complex tables.'), '#default_value' => $this->options['summary'], ); } diff --git a/plugins/views_plugin_style_table.inc b/plugins/views_plugin_style_table.inc index 98919ab..45ed976 100644 --- a/plugins/views_plugin_style_table.inc +++ b/plugins/views_plugin_style_table.inc @@ -33,6 +33,7 @@ class views_plugin_style_table extends views_plugin_style { $options['override'] = array('default' => TRUE, 'bool' => TRUE); $options['sticky'] = array('default' => FALSE, 'bool' => TRUE); $options['order'] = array('default' => 'asc'); + $options['caption'] = array('default' => '', 'translatable' => TRUE); $options['summary'] = array('default' => '', 'translatable' => TRUE); $options['empty_table'] = array('default' => FALSE, 'bool' => TRUE); @@ -179,10 +180,18 @@ class views_plugin_style_table extends views_plugin_style { '#description' => t('(Sticky header effects will not be active for preview below, only on live output.)'), ); + $form['caption'] = array( + '#type' => 'textfield', + '#title' => t('Short description of table'), + '#description' => t('Include a caption for better accessibility of your table.'), + '#default_value' => $this->options['caption'], + '#maxlength' => 255, + ); + $form['summary'] = array( '#type' => 'textfield', '#title' => t('Table summary'), - '#description' => t('This value will be displayed as table-summary attribute in the html. Set this for better accessiblity of your site.'), + '#description' => t('This value will be displayed as table-summary attribute in the html. Use this to give a summary of complex tables.'), '#default_value' => $this->options['summary'], '#maxlength' => 255, ); diff --git a/theme/theme.inc b/theme/theme.inc index 52598d5..6708c03 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -399,6 +399,9 @@ function template_preprocess_views_view_summary(&$vars) { $vars['row_classes'][$id] = 'active'; } } + + $vars['caption'] = filter_xss_admin($handler->options['caption']); + } /** @@ -449,6 +452,8 @@ function template_preprocess_views_view_summary_unformatted(&$vars) { $vars['row_classes'][$id] = 'active'; } } + + $vars['caption'] = filter_xss_admin($handler->options['caption']); } /** @@ -652,6 +657,11 @@ function template_preprocess_views_view_table(&$vars) { if (!empty($handler->options['summary'])) { $vars['attributes_array'] = array('summary' => $handler->options['summary']); } + + // Add the caption to the list if set. + if (!empty($handler->options['caption'])) { + $vars['attributes_array'] = array('caption' => $handler->options['caption']); + } } /** @@ -762,9 +772,15 @@ function template_preprocess_views_view_grid(&$vars) { } $vars['rows'] = $rows; $vars['class'] = 'views-view-grid cols-' . $columns; + if (!empty($handler->options['summary'])) { $vars['attributes_array'] = array('summary' => $handler->options['summary']); } + + // Add the caption to the list if set. + if (!empty($handler->options['caption'])) { + $vars['attributes_array'] = array('caption' => $handler->options['caption']); + } } /** diff --git a/theme/views-view-grid.tpl.php b/theme/views-view-grid.tpl.php index cd8d39e..09f807a 100644 --- a/theme/views-view-grid.tpl.php +++ b/theme/views-view-grid.tpl.php @@ -14,6 +14,10 @@

> + + + + $columns): ?> > diff --git a/theme/views-view-table.tpl.php b/theme/views-view-table.tpl.php index a9abcd3..4fec9fa 100644 --- a/theme/views-view-table.tpl.php +++ b/theme/views-view-table.tpl.php @@ -6,6 +6,7 @@ * * - $title : The title of this group of rows. May be empty. * - $header: An array of header labels keyed by field id. + * - $caption: The caption for this table. May be empty. * - $header_classes: An array of header classes keyed by field id. * - $fields: An array of CSS IDs to use for each field id. * - $classes: A class or classes to apply to the table, based on settings. @@ -19,8 +20,8 @@ */ ?>
> - - + + -- 1.7.0.4