Roots Discourse

Using ACF Builder with Sage


#21

@Log1x this looks awesome! I installed and I’m trying it out, but I can’t seem to get any output. I created a foreach loop that is pulling in partials based on acf_fc_layout (based on the recommendations of nathobson and jasonbaciulis):

@foreach ($components as $component)
  @include('partials/builder/'.$component->acf_fc_layout)
@endforeach

Here are the contents of the partial, which is successfully loading, but not printing any of the field values:

<div class="image-text-overlay">
  @group('image-text-overlay')
    <div>
      <h2>@sub('heading')</h2>
    </div>
    <div><img src="@sub('image', 'url')" alt="@sub('image','alt')"></div>
  @endgroup
  @debug
</div>

Here’s what’s in debug:

Anything I might be missing?


#22

Did you figure this out? Is the group key supposed to be image_text_overlay?

Does {!! var_dump(have_rows('image-text-overlay')) !!} return true?

For what it’s worth, https://github.com/Log1x/sage-directives now has docs & has been updated. :slight_smile:


#24

Hey Brandom, I really appreciate your effort to help us write such cleaner and more maintainable code. Although there’s one big gotcha that took me hours to debug that I think you should warn people when using this technique. It took me a long time to figure out why the custom fields were not working in a production server but were working in my local mac environment, it turned out to be all about the letter case in the file and folder names.

As a quick example, if you create a file named Button.php and try to call get_field_partial('components.button') , it won’t work because it will look for a button.php (lower cased). Same thing for folder names such as Fields and fields .

I think that because all other files and folders around the app folder are all capitalized (since they are classes), I also happened to capitalized the custom fields. Big problem is that it didn’t care at all in my mac environment, but the moment I’ve uploaded it to the linux production server nothing worked hehe, taking some good hours to find out why and update everything.

Thanks again for the awesome article!


#25

I want to reuse fields on multiple options pages.
The catch is that options are basically all one page as far as ACF is concerned, so they need unique keys per options page.

I’m adding normal fields, not flexible content fields.

I tried both the ->addFields($header) method and the ->addFields(get_field_partial('partials.header')) method, and tried setting the ‘key’ on the FieldsBuilder and addFields.

With the above attempts, the same keys get used (can tell this quickly because the fields on new options pages are filled out already with text i entered through wp-admin on old options pages)

Is there a way to add a prefix to the key or change the key after doing addFields? I don’t see any mention in the ACFBuilder docs about prefixing a key. Or am I going about this the wrong way?

Thanks

Edit: This seems more of an ACFBuilder question so I submitted it on their repo. I’ll update here if a solution is found.


#26

With the current implementation of ->addFields, I don’t see a sane way in ACF Builder’s source to pull this off for the entire field group; especially with the FieldsBuilder instance protecting $config and $fieldManager.

I can see this being useful if implemented though as shown in the issue you opened.


#27

5.7.10 release right now! It solves several Gutenberg issues:

  • Fix - Fixed bug preventing metaboxes from saving if validation fails within Gutenberg.
  • Fix - Fixed bug causing unload prompt to show incorrectly within Gutenberg.
  • Fix - Fixed JS error when selecting taxonomy terms within Gutenberg.
  • Fix - Fixed bug causing jQuery sortable issues within other plugins.
  • Tweak - Improved loading translations by adding fallback from region to country when .mo file does not exit.
  • Tweak - Improved punctuation throughout admin notices.
  • Tweak - Improved performance and accuracy when loading a user field value.
  • Dev - Added filter ‘acf/get_locale’ to customize the locale used to load translations.
  • Dev - Added filter ‘acf/allow_unfiltered_html’ to customize if current user can save unfiltered HTML.
  • Dev - Added new data storage functions acf_register_store() and acf_get_store().
  • Dev - Moved from .less to .scss and minified all css.
  • i18n - Updated French translation thanks to Maxime Bernard-Jacquet.
  • i18n - Updated Czech translation thanks to David Rychly.

@zack


#28

Hey, After following Brandon’s guide I am having an issue. I can create fields and they display in WordPress backend, however, the problem is with Media. No image is showing and the loading circle is swirling all the time.
I also notice that removing the code from the bottom of setup.php file helps (code below), but of course, it is necessary to use the builder.
Any ideas how to resolve this problem guys? Is any of you had this problem.

PS. I am using WP 5.0.3

/**
* Initialize ACF Builder
*/
add_action('init', function () {
    collect(glob(config('theme.dir').'/app/fields/*.php'))->map(function ($field) {
        return require_once($field);
    })->map(function ($field) {
        if ($field instanceof FieldsBuilder) {
            acf_add_local_field_group($field->build());
        }
    });
});

#29

Not really sure why that is happening, but there’s either a PHP error which should be in your error log or a JS error which would be in devtools console. If so, can you share them?