Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cater for field type flexible_content #6

Open
bobbingwide opened this issue Jun 14, 2023 · 2 comments
Open

Cater for field type flexible_content #6

bobbingwide opened this issue Jun 14, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Jun 14, 2023

The flexible_content field type is similar to the repeater field type.

You need to define one or more layouts in order for the Add Row button to display the layout type you want to add.

The field_info structure contains layouts which is a multi-dimensional associative array of layout arrays which contain an array of sub_fields within the layout.

@bobbingwide bobbingwide added the enhancement New feature or request label Jun 14, 2023
@bobbingwide bobbingwide self-assigned this Jun 14, 2023
@bobbingwide
Copy link
Owner Author

Example with one layout labelled Layout 1 (layout_1) that contains a text field called flexible_content_text.

 [layouts] => Array

        [layout_64896c6264a66] => Array

            [key] => (string) "layout_64896c6264a66"
            [name] => (string) "layout_1"
            [label] => (string) "Layout 1"
            [display] => (string) "row"
            [sub_fields] => Array

                [0] => Array

                    [ID] => (integer) 420
                    [key] => (string) "field_64896c7faa275"
                    [label] => (string) "Flexible Content Text"
                    [name] => (string) "flexible_content_text"
                    [aria-label] => (string) ""
                    [prefix] => (string) "acf"
                    [type] => (string) "text"
                    [value] => (NULL) 
                    [menu_order] => (integer) 0
                    [instructions] => (string) ""
                    [required] => (integer) 0
                    [id] => (string) ""
                    [class] => (string) ""
                    [conditional_logic] => (integer) 0
                    [parent] => (integer) 419
                    [wrapper] => *RECURSION* wrapper 0
                    [parent_layout] => (string) "layout_64896c6264a66"
                    [default_value] => (string) "FCT"
                    [maxlength] => (string) ""
                    [placeholder] => (string) ""
                    [prepend] => (string) ""
                    [append] => (string) ""
                    [_name] => (string) "flexible_content_text"
                    [_valid] => (integer) 1


            [min] => (string) ""
            [max] => (string) ""

@bobbingwide
Copy link
Owner Author

The value of $field is an array of the sections. The first item in each section is the name of the layout to use to display the section acf_fc_layout. The subsequent items are the values of the fields in that section/layout.

Array

    [0] => Array

        [acf_fc_layout] => (string) "layout_1"
        [flexible_content_text] => (string) "FCT 1"

    [1] => Array

        [acf_fc_layout] => (string) "layout_1"
        [flexible_content_text] => (string) "FCT 2"

In the prototype for this block's output we'll render each section as a div with a classname of the selected layout ( acf_fc_layout ) then render each of the sub_fields in the layout, obtaining the values for the field from the section's array.

bobbingwide added a commit that referenced this issue Jul 8, 2023
bobbingwide added a commit that referenced this issue Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant