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

Best practise for Flexible Content #257

Closed
simondotwhite opened this issue Jun 13, 2024 · 5 comments
Closed

Best practise for Flexible Content #257

simondotwhite opened this issue Jun 13, 2024 · 5 comments

Comments

@simondotwhite
Copy link

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
Copy link
Owner

Log1x commented Jun 13, 2024

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

@Log1x
Copy link
Owner

Log1x commented Jun 13, 2024

Oh, I think you can just pass the partial straight to ->addLayout now the same as my addPartial example above:

public function addLayout($layout, $args = [])
{
$layout = is_a($layout, FieldsBuilder::class)
? clone $layout
: Builder::make($layout, $args);
$layout = $this->initializeLayout($layout, $args);
$this->pushLayout($layout);
return $layout;
}

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

@Log1x
Copy link
Owner

Log1x commented Jun 13, 2024

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
Copy link
Author

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
Copy link
Owner

Log1x commented Jun 13, 2024

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

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