From 2d8c545c123cbeee7cdfda4f4ec9d62c6c4f2c50 Mon Sep 17 00:00:00 2001 From: jeremyfelt Date: Tue, 5 Mar 2013 20:44:39 -0800 Subject: [PATCH] Track row actions output on each row to catch cases where custom output may not be added When a provider class does not provide a method to output one of its registered columns, our list table should account for the possible lack of row actions. This commit adds a tracking property for the display of row actions. If a column's output is not handled by the provider class and row actions have not yet been displayed, we handle output of the row actions. Once row actions have been output once, the flag is maintained throughout the row. When the row is complete, the flag is reset for the next. One quirk - if a provider class handles the output for the first column, but does not handle row actions, and does not handle the output for the next column, row actions will be output in that second column. This feels a little weird, but I think gets us close enough. Fixes #51 --- common/lib/acm-wp-list-table.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/common/lib/acm-wp-list-table.php b/common/lib/acm-wp-list-table.php index a795ef1..897f3cf 100644 --- a/common/lib/acm-wp-list-table.php +++ b/common/lib/acm-wp-list-table.php @@ -15,6 +15,13 @@ class ACM_WP_List_Table extends WP_List_Table { + /** + * Row actions should be displayed once per row. This tracks if the row + * action method has been accessed. + * @var bool + */ + var $row_actions_processed = false; + function __construct( $params = array() ) { parent::__construct( $params ); } @@ -141,6 +148,9 @@ function single_row( $item ) { echo ''; echo $this->single_row_columns( $item ); echo ''; + + // Reset to false after each row is complete + $this->row_actions_processed = false; } /** @@ -162,10 +172,12 @@ function column_default( $item, $column_name ) { case 'operator': return ( ! empty( $item['operator'] ) ) ? $item['operator'] : $ad_code_manager->logical_operator; default: - // @todo need to make the first column (whatever it is filtered) to show row actions // Handle custom columns, if any - if ( isset( $item['url_vars'][$column_name] ) ) - return esc_html( $item['url_vars'][$column_name] ); + if ( isset( $item['url_vars'][ $column_name ] ) ) { + $output = esc_html( $item['url_vars'][ $column_name ] ); + $output .= $this->row_actions_output( $item ); + return $output; + } break; } @@ -293,6 +305,12 @@ function column_conditionals( $item ) { */ function row_actions_output( $item ) { + // If row actions have already been processed for this row, return an empty string, + if ( $this->row_actions_processed ) + return ''; + else + $this->row_actions_processed = true; + $output = ''; // $row_actions['preview-ad-code'] = '' . __( 'Preview Ad Code', 'ad-code-manager' ) . ''; $row_actions['edit'] = '' . __( 'Edit Ad Code', 'ad-code-manager' ) . '';