acf-builder icon indicating copy to clipboard operation
acf-builder copied to clipboard

Adding the file field type

Open broskees opened this issue 6 years ago • 3 comments

I can't find any documentation on the File Field Type. This is the syntax I have currently, and it doesn't seem to be working. What's the correct syntax:

$formFields = new StoutLogic\AcfBuilder\FieldsBuilder('columns');
$formFields
    ->addFile('Associated PDF Form');

function form_pages() {
    include( dirname( __FILE__ ) . '/partials/form_pages_vars.php');

    $form_pages = new FieldsBuilder('form_pages', [
        'title' => 'PDF Version of Form',
        'style' => 'seemless',
        'layout' => 'row',
    ]);
    $form_pages
        ->setLocation('post', '==', '356')
            ->or('post'. '=='. '246')
        ->addFields($formFields);

    return $form_pages;
}

acf_add_local_field_group( form_pages()->build() );

broskees avatar Oct 19 '18 19:10 broskees

@broskees The addFile method you're using does exist, you can see it here: https://github.com/StoutLogic/acf-builder/blob/master/src/FieldsBuilder.php#L314

I believe the issue is accessing the $formFields variable, which defined outside the scope of the form_pages function. See: https://secure.php.net/manual/en/language.variables.scope.php

What is the output from print_r(form_pages()->build()); ?

stevep avatar Oct 19 '18 19:10 stevep

I seemed to fix the issue by moving the code around. What you see above wasn't exactly an accurate representation of the code.

This is where it stands now:

// DEFINE FIELD
$form_pages = new StoutLogic\AcfBuilder\FieldsBuilder('form_pages', [
    'title' => 'PDF Version of Form',
    'style' => 'seemless',
    'layout' => 'row',
]);

//FIELD SETTINGS
$form_pages
    ->setLocation('post', '==', '356')
        ->or('post'. '=='. '246')
    ->addFile('pdf_form', [
        'title' => 'Associated PDF Form',
        'layout' => 'block'
    ]);

Now my issue is that the field only shows up on post with id 356 and not the other one?

Any idea why that might be?

broskees avatar Oct 25 '18 17:10 broskees

Syntax error. Figured it out. Thank you!

broskees avatar Oct 25 '18 17:10 broskees