I’m working on several new field types: fields that would allow me to easilly define properties such as padding, margin, text align for each CSS breakpoint of my framework. For context, you can:
1) Check out a screenshot of what the field (a text align field) looks like here: https://github.com/foyle82/acf-test-conditional/blob/main/screen.jpg
2) Download a simplified version of said field pruned of any superfluous feature here: https://github.com/foyle82/acf-test-conditional
Now i have two very specific questions:
function render_field( $field ) {
acf_render_field_wrap( [
'type' => 'group',
'name' => $this->field['name'],
'value' => $this->field['value'],
'label' => __( 'Group', 'acf' ),
'sub_fields' => []
] );
}
Question #1: Group field as wrapper
For context see: https://github.com/foyle82/acf-test-conditional/blob/main/fields/field.php#L24-L31
I’m going to rely on some conditional logic in order to show/hide fields. I found out that using acf_render_field_wrap()
(while inside of render_field()
), defining a group and populating the subfields as I please, does seem to work properly. Since I found no documentation that either describes or discourages this solution I would like to know if this is a correct approach or if it may lead to issues down the line.
function render_field( $field ) {
acf_render_field_wrap( [
'type' => 'group',
'name' => $this->field['name'],
'value' => $this->field['value'],
'label' => __( 'Group', 'acf' ),
'sub_fields' => [
[
'label' => 'Select',
'name' => 'select',
'key' => 'select',
'type' => 'select',
'choices' => [],
]
]
] );
}
Question #2: Sub field keys
For context see: https://github.com/foyle82/acf-test-conditional/blob/main/fields/field.php#L33-L47
Each subfield of the above group, currently uses the same “name” and “key” keys (note that this does not apply to the parent group field, just to the inner subfields). Everything works properly and proves easier to handle (expecially when it comes to generating fields on the fly depending on the number/name of breakpoints supported by the current theme). Hence the question is: can this approach lead to future issues or is it well supported and safe to use?
Thanks in advance.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.