All Fields Customization

I have added the following snippet to functions.php in order to overwrite the output of a fileupload field, when using the all_fields output with Advanced Post Creation.

add_filter( 'gform_merge_tag_filter', function ( $value, $merge_tag, $modifier, $field, $raw_value, $format ) {
    if ( $merge_tag == 'all_fields' && $field->type == 'fileupload' ) {
        $value    = 'This contains attached files. Contact us for more information.';
    }
     return $value;
}, 10, 6 );

Which appeared to be working great. However, I am now seeing that it’s outputting whether the form had files uploaded or not.

Please lend your thoughts on making this conditional to when files are uploaded — I’m juggling a lot at the moment and some help on this one would be very much appreciated.

Much thanks
CT

Might the following tweak address things?

if ( $merge_tag == 'all_fields' && $field->type == 'fileupload' && ! empty( $raw_value ) ) {

Tried that just now and no change