Log1x / acf-composer

Compose ACF Fields, Blocks, Widgets, and Option Pages with ACF Builder on Sage 10.
https://github.com/Log1x/acf-composer
MIT License
417 stars 57 forks source link

Best practise for Flexible Content #257

Closed simondotwhite closed 1 month ago

simondotwhite commented 3 months ago

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

Log1x commented 3 months ago

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

Log1x commented 3 months ago

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 commented 3 months ago

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

simondotwhite commented 3 months ago

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!

Log1x commented 3 months ago

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