NO BUG: Meta Box Integration: Fatal Error with File Advanced Field within a MB Group

Hello,

I have a “File Advanced” (with max number of files 1) type within a MB group, like so:

And within my Bricks template I’m just using a condition with Dynamic Data to check if I have some file within my File Advanced MB field like so:
image

And on the front-end I have a Fatal error: Uncaught Error: array_values(): Argument #1 ($array) must be of type array, int given
in …/wp-content/themes/bricks/includes/integrations/dynamic-data/providers/provider-metabox.php on line 210

Can this be fixed in the v1.8 please?

Thanks :slight_smile:

For reference, since the latest Meta Box version, they provided the code within “Theme Code” metabox.

The code provided for the file advanced within the group is this:

<?php
$group = rwmb_meta( 'documents_step_1' );

// Field der:
$file_ids = $group[ 'der' ] ?? [];
?>
<h3>Uploaded files</h3>
<ul>
	<?php foreach ( $file_ids as $file_id ) : ?>
		<?php $file = RWMB_File_Field::file_info( $file_id ); ?>
		<li><a href="<?= $file['url']; ?>"><?= $file['name']; ?></a></li>
	<?php endforeach ?>
</ul>

It’s wrong and I notified the Meta Box theme, it should have been this instead or something similar: Updated Theme Code for MB File Advanced within a MB Group - Pastebin.com

In your file “/bricks/includes/integrations/dynamic-data/providers/provider-metabox.php” at line 210 you have this at the moment (in v1.7.3):

You shouldn’t assume that $value is an array, since in my case the field type “file_advanced” is returning the ID (so an integer) of the media.

You could modify the code like so, so there no error is $value is not an array:
image

Thank you :slight_smile:

Support ticket on Meta Box forum : Theme code is wrong about a File Advanced field within a Group - Meta Box

I’m thinking even though the File Advanced having 1 max number of file, they should have returning an array of just one item and then we wouldn’t even have this error with Bricks.

But that shouldn’t prevent Bricks to implement the safe road of checking if value is still an array before using array function with the variable… :stuck_out_tongue:

Hi @Adrien ,

Thanks for reaching out.

Unfortunately, I set up a file advanced file inside a group, limiting it to max 1 file, and try using the dynamic data inside the condition but no Fatal error at all.

  1. May I know where you place the condition? Inside the Group loop or outside the Group loop?
  2. Seems like the Metabox Theme code providing the correct code. When you var_dump rwmb_meta( 'documents_step_1' ); You should get the result in an array if you uploaded a file, otherwise, it will be an empty string.
  3. Bricks is not using Metabox Theme code’s code to parse the dynamic data, so it should not be affected.
  4. Based on your screenshot, you are using {mb_dossier-client_documents_step_1_fiche_client}, it seems like not your DER field as per your screenshot.

Could you provide a temp admin access + FTP (as your site will encounter a fatal error) and send it to help@bricksbuilder.io ?

Kindly include this forum thread in your email as a reference as well :slight_smile:

Regards,
Jenn

Hi @itchycode,

  1. It’s place on a button, my group isn’t cloneable so I’m not querying it, I’m trying to use the subfield of the group directly
    image
    Here is my structure:


  2. Yeah I get an array, that’s why I can get the ‘der’ index inside my array $group, like on their screenshot, but I have only the ID after that
    image
    image


    That’s why I can foreach on an ID

  3. Alright, nevertheless I have the error when trying to access the subfield of a MB Group (not cloneable) within Bricks Condition

  4. It’s another File Advanced within my Group so it’s the same


Email sent (SFTP should not be needed since you just have to remove the condition on the DER block, save again and that’s not an issue anymore on the “dossier-client” entry (which I forgot to say should be at step 2, but I’ve explained that you need to download the PDF template and upload them back on the same page and submit it so the entry goes to step 2 automatically))
image

1 Like

The issue is coming from WS Form (I’m using it to upload the PDF through a front-end form) that change the way the data are stored, so no issue from Bricks, this topic can be closed.

Thanks for @itchycode for the solid support once again!

1 Like

Hey Adrien, you are most welcome :slight_smile: