Last active
May 19, 2019 23:42
-
-
Save jakejackson1/58c52c5ef5cefd009291780bdb94f307 to your computer and use it in GitHub Desktop.
Convert Multi-Column List to Single Column
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'gfpdf_pdf_field_content', function( $value, $field, $entry, $form, $pdf_field ) { | |
if ( $field->type === 'list' ) { | |
/* get out field value */ | |
$value = $pdf_field->value(); | |
$columns = is_array( $value[0] ); | |
/* exit early if list field is empty */ | |
if ( $pdf_field->is_empty() || ! $columns ) { | |
return ''; | |
} | |
$columns = array_keys( $value[0] ); | |
/* Start buffer and generate a list table */ | |
ob_start(); | |
?> | |
<table autosize="1" class="gfield_list"> | |
<tbody class="contents"> | |
<?php foreach ( $value as $item ) : ?> | |
<?php foreach ( $columns as $column ) : ?> | |
<tr> | |
<th> | |
<?php echo esc_html( $column ); ?> | |
</th> | |
</tr> | |
<tr> | |
<td> | |
<?php echo esc_html( rgar( $item, $column ) ); ?> | |
</td> | |
</tr> | |
<?php endforeach; ?> | |
<?php endforeach; ?> | |
</tbody> | |
</table> | |
<?php | |
return ob_get_clean(); | |
} | |
return $value; | |
}, 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment