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
398 stars 53 forks source link

Fieldgroup position #242

Closed Coders91 closed 2 months ago

Coders91 commented 2 months ago

Sorry but I really can't seem to find where to include the position for a created field group. I tried passing it in field class $defaults = ['location' => 'side'] but this gives an error Type of App\Fields\Sidebar::$defaults must be Illuminate\Support\Collection|array (as in class Log1x\AcfComposer\Composer). Also tried guessing a method $sidebar->setPosition('side') and $sidebar ->setGroupConfig('position', 'side');

Log1x commented 2 months ago

Something like this should do the trick:

$company = Builder::make('company', [
    'acfe_display_title' => 'Page Settings',
    'position' => 'side',
]);
Coders91 commented 2 months ago

Thank you, doesn't seem to be working though. Full code:

namespace App\Fields;

use Log1x\AcfComposer\Builder;
use Log1x\AcfComposer\Field;

class Sidebar extends Field
{
    /**
     * The field group.
     */
    public function fields(): array
    {
        $sidebar = Builder::make('sidebar', [
            'position' => 'side',
        ]);

        $sidebar
            ->setLocation('post_type', '==', 'page');

        $sidebar
            ->addSelect('select_field', [
              'label' => 'Select Field',
              'required' => 0,
              'choices' => $this->sidebars(),
              'default_value' => 'none',
              'allow_null' => 1,
              'multiple' => 0,
              'ui' => 1,
              'ajax' => 0,
              'placeholder' => 'Select a sidebar',
          ]);

        return $sidebar->build();
    }
Log1x commented 2 months ago

Hmm, have you ran acorn acf:cache at any point? If so, you might need to clear it with acf:clear – otherwise I'm not sure why this wouldn't be working. I have a project with a few fields in the sidebar of a custom post type and if I remove 'position' => 'side', it moves it back to the bottom of the editor, and re-adding it is putting it back in the sidebar as intended. 😕

Coders91 commented 2 months ago

Removing the existing page and adding new one does put the field in the sidebar. Thank you for your quick support and everything we can use :).