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

Flexible content with partials - Can't get it to work #175

Closed
PetteriSeoka opened this issue Aug 16, 2023 · 2 comments
Closed

Flexible content with partials - Can't get it to work #175

PetteriSeoka opened this issue Aug 16, 2023 · 2 comments

Comments

@PetteriSeoka
Copy link

Hi!

First of all, great tool for ACF!

I have a slight problem. I'm trying to create a pagebuilder where I keep the layouts in separate partials. I have read your readme file and searched in endlessly in the Sage community without solving this issue. Could you please point me to the right direction?

Much appreciated,

Petteri


Test.php

<?php

namespace App\Fields;

use Log1x\AcfComposer\Field;
use StoutLogic\AcfBuilder\FieldsBuilder;
use App\Fields\Partials\Builder;
use App\Fields\Partials\Text;
use App\Fields\Partials\ListItems;


class Test extends Field
{
    /**
     * The field group.
     *
     * @return array
     */
    public function fields()
    {

        $test = new FieldsBuilder('Sidbyggare');

        $test
            ->setLocation('post_type', '==', 'page')
            ->and('post', '==', '2');
        
        $test
            ->addFields($this->get(Builder::class))

            ->addFields($this->get(ListItems::class));

        return $test->build();
    }
}

Builder.php

<?php

namespace App\Fields\Partials;

use Log1x\AcfComposer\Partial;
use StoutLogic\AcfBuilder\FieldsBuilder;
use App\Fields\Partials\Text;


class Builder extends Partial
{
    /**
     * The partial field group.
     *
     * @return \StoutLogic\AcfBuilder\FieldsBuilder
     */
    public function fields()
    {

        $builder = new FieldsBuilder('builder');

        $builder
            ->addFlexibleContent('komponenter', [
                'button_label' => 'Lägg till komponent',
            ])

            ->addFields($this->get(Text::class))
            ->endFlexibleContent();

            

        
        return $builder;
    }
}          

Text.php

<?php

namespace App\Fields\Partials;

use Log1x\AcfComposer\Partial;
use StoutLogic\AcfBuilder\FieldsBuilder;

class Text extends Partial
{
    /**
     * The partial field group.
     *
     * @return \StoutLogic\AcfBuilder\FieldsBuilder
     */
    public function fields()
    {
        $text = new FieldsBuilder('text');

        $text
            ->addLayout('layout', [
                'label' => 'Layout',
                'display' => '',
                'sub_fields' => [],
                'min' => '',
                'max' => '',
            ])
            ->addText('title')
            ->setWidth('30')
            ->addWysiwyg('content')
            ->setWidth('30')
            ->addRange('width');

        return $text;
    }
}
@Log1x
Copy link
Owner

Log1x commented Aug 25, 2023

I haven't used flexible content fields in awhile but as far as I know you need to remove ->addLayout() from $text:

$text = new FieldsBuilder('text');

$text
    ->addText('title')
    ->setWidth('30')
    ->addWysiwyg('content')
    ->setWidth('30')
    ->addRange('width');

return $text;

and then use ->addLayout on your $builder:

$builder = new FieldsBuilder('builder');

$builder
    ->addFlexibleContent('komponenter', [
        'button_label' => 'Lägg till komponent',
    ])
        ->addLayout($this->get(Text::class))
    ->endFlexibleContent();

@PetteriSeoka
Copy link
Author

Great! This worked! Thanks! :)

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