Skip to content

Commit

Permalink
Track row actions output on each row to catch cases where custom outp…
Browse files Browse the repository at this point in the history
…ut 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
  • Loading branch information
jeremyfelt committed Mar 6, 2013
1 parent 11a7efd commit 2d8c545
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions common/lib/acm-wp-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -141,6 +148,9 @@ function single_row( $item ) {
echo '<tr id="ad-code-' . $item['post_id'] . '"' . $row_class . '>';
echo $this->single_row_columns( $item );
echo '</tr>';

// Reset to false after each row is complete
$this->row_actions_processed = false;
}

/**
Expand All @@ -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;
}

Expand Down Expand Up @@ -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'] = '<a class="acm-ajax-preview" id="acm-preview-' . $item[ 'post_id' ] . '" href="#">' . __( 'Preview Ad Code', 'ad-code-manager' ) . '</a>';
$row_actions['edit'] = '<a class="acm-ajax-edit" id="acm-edit-' . $item[ 'post_id' ] . '" href="#">' . __( 'Edit Ad Code', 'ad-code-manager' ) . '</a>';
Expand Down

0 comments on commit 2d8c545

Please sign in to comment.