acf-composer icon indicating copy to clipboard operation
acf-composer copied to clipboard

Best practise for Flexible Content

Open simondotwhite opened this issue 1 year ago • 5 comments

Hey,

Looking through some of the code and issues it seems like #175 is the most up to date information it. But in the code, it says that $this->get() is deprecated.

Is there a better/more up-to-date way of adding partials as layouts when using Flexible Content?

Cheers

simondotwhite avatar Jun 13 '24 13:06 simondotwhite

It should be simplified to $example->addPartial(YourPartial::class) now.

Log1x avatar Jun 13 '24 13:06 Log1x

Oh, I think you can just pass the partial straight to ->addLayout now the same as my addPartial example above: https://github.com/Log1x/acf-composer/blob/284c40b61e6efeea0995f1c0951c9606b7d021e1/src/Builder/FlexibleContentBuilder.php#L64-L75

Sorry, I never use Flexible Content anymore so I couldn't entirely remember. #252 should fix this.

Log1x avatar Jun 13 '24 13:06 Log1x

Also, assuming all works well – we can probably get a rule for that in the upgrade command.

https://github.com/Log1x/acf-composer/blob/master/src/Console/UpgradeCommand.php#L49

Log1x avatar Jun 13 '24 14:06 Log1x

Hey, thanks for coming back to me. When I try to pass the partial class in like this

->addLayout(Text::class)

It wasn't working. Although the following does, so maybe I've misunderstood.

class PageBuilder extends Partial
{
    public function fields()
    {
        $pageBuilder = Builder::make('pageBuilder');

        $pageBuilder
            ->addFlexibleContent('components', ['label' => 'Blocks'])
            ->addLayout('Text')->addPartial(Text::class)
            ->endFlexibleContent();

        return $pageBuilder;
    }
}

Thanks for your help!

simondotwhite avatar Jun 13 '24 14:06 simondotwhite

Ah I see. It's good the latter works – but I think we can make it a bit better in the future. 👍

Log1x avatar Jun 13 '24 14:06 Log1x