StoutLogic / acf-builder

An Advanced Custom Field Configuration Builder
GNU General Public License v2.0
794 stars 62 forks source link

Can not determine field key for repeater's collapsed value #171

Open joseph-farruggio opened 1 year ago

joseph-farruggio commented 1 year ago

I have a repeater priority_ads and I want the collapsed value to be the ad_title subfield's key. I'm having trouble determining the field's key. The field is added to the repeater using addFields().

I've tried multiple variations of field keys using these docs: https://github.com/StoutLogic/acf-builder/wiki/generated-keys https://github.com/StoutLogic/acf-builder/wiki/composing-fields#generated-keys

I get an error each time that the field (based on the key I provided) does not exist.

I've created a simplified version of my implementation:

<?php
use StoutLogic\AcfBuilder\FieldsBuilder;

/**
 * Subfield template
 */
$ad_set = new FieldsBuilder('ad_set');
$ad_set
    ->addTab('ad_content')
    ->addText('ad_title', ['wrapper' => ['width' => '50%']]);

/**
 * Field group with repeater
 */
$wp_custom_ads = new StoutLogic\AcfBuilder\FieldsBuilder('wp_custom_ads');
$wp_custom_ads
    ->addRepeater('priority_ads', ['layout' => 'block', 'button_label' => 'New Ad', 'collapsed' => 'FIELD_KEY_HERE'])
    ->addFields($ad_set)
    ->setLocation('options_page', '==', 'wp-custom-ads');

add_action('acf/init', function () use ($wp_custom_ads) {
    acf_add_local_field_group($wp_custom_ads->build());
});
stevep commented 1 year ago

Hey @joseph-farruggio I agree the docs probably aren't clear on this, but I tried your example using ad_title as the collapsed key and it worked for me. But maybe in your more complicated example there is another issue?

Screenshot 2023-03-29 at 9 52 10 AM
/**
  * Subfield template
  */
$ad_set = new FieldsBuilder('ad_set');
$ad_set
  ->addTab('ad_content')
  ->addText('ad_title', ['wrapper' => ['width' => '50%']]);

/**
  * Field group with repeater
  */
$wp_custom_ads = new FieldsBuilder('wp_custom_ads');
$wp_custom_ads
  ->addRepeater(
    'priority_ads',
    ['layout' => 'block', 'button_label' => 'New Ad', 'collapsed' => 'ad_title']
  )
  ->addFields($ad_set)
  ->setLocation('options_page', '==', 'wp-custom-ads');

add_action('acf/init', function () use ($wp_custom_ads) {
    acf_add_local_field_group($wp_custom_ads->build());
});
joseph-farruggio commented 1 year ago

That works, thanks!

Based on the docs, I thought it had to be prepended with field_.