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

Nested inner blocks #230

Closed
marcbelletre opened this issue Mar 6, 2024 · 2 comments
Closed

Nested inner blocks #230

marcbelletre opened this issue Mar 6, 2024 · 2 comments

Comments

@marcbelletre
Copy link
Contributor

Hi @Log1x,

I would like to build a block that is based on the core/media-text block. I didn't find any documentation about this but after digging into the source code I found out that it was possible to do so using an innerBlock property. My first attempt was to use it like below:

/**
 * The block attributes.
 */
public function attributes(): array
{
    return [
        'template' => [
            // ...
            'core/media-text' => [
                'mediaType' => 'image',
                'mediaWidth' => 25,
                'innerBlocks' => [
                    'core/heading' => ['placeholder' => 'Hello World'],
                    'core/paragraph' => ['placeholder' => 'Welcome to the Team Member block.'],
                ],
            ],
        ],
    ];
}

Because of the line that collapses the collection here it is necessary to wrap each block into a single array to make it work.

'innerBlocks' => [
    [
        'core/heading' => ['placeholder' => 'Hello World'],
    ],
    [
        'core/paragraph' => ['placeholder' => 'Welcome to the Team Member block.'],
    ],
],

If I remove the collapse() method the first approach works fine. So I'm just wondering if it is here for a reason? If not, should we remove it?

Cheers, and thank you for this awesome package! 🚀

@Log1x
Copy link
Owner

Log1x commented Mar 6, 2024

If I remove the collapse() method the first approach works fine.

I think I had to do this due to group/column blocks. Check out #159 for more details.

This feature wasn't released til v3 so I'm open to changing it/making it better – I just want to make sure it keeps support for everything.

I didn't find any documentation about this

ACF Composer has outgrown the README. I plan to put up real docs soon.

@marcbelletre
Copy link
Contributor Author

I was about to make some tests to see if uncollapsing the collection was also working with groups and columns. Then I realized there is a very simple reason why we can't use the slugs as keys.

This would not work because of the duplicated key:

'innerBlocks' => [
    'core/heading' => ['placeholder' => 'Hello World'],
    'core/paragraph' => ['placeholder' => 'This is the first paragraph'],
    'core/paragraph' => ['placeholder' => 'This is the second paragraph'],
],

This does:

'innerBlocks' => [
    ['core/heading' => ['placeholder' => 'Hello World']],
    ['core/paragraph' => ['placeholder' => 'This is the first paragraph']],
    ['core/paragraph' => ['placeholder' => 'This is the second paragraph']],
],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants