Using ACF Builder with Sage

I’m trying to understand, And I see what I did wrong in my last example. So I tried starting only with a Field, and a partial. And instead of adding it to a block, I just added to post_type page. And the partial just wont show up inside the field. Only the empty field shows up without the field set in the partial. I don’t know what I am doing wrong here. I basically copy pasted code from the docs, and I only changed the ‘example’ to my own name.

See the attached image (and yes I did expand the fieldgroup.

My Field

<?php

namespace App\Fields\Partials;

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

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

        $blockImageCaption
            ->addImage(
                'image',
                [
                    'label' => 'Afbeelding',
                    'instructions' => 'Afbeelding met bijbehorende caption',
                    'required' => 1,
                    'return_format' => 'array',
                    'preview_size' => 'medium',
                    'library' => 'all',
                ]
            );

        return $blockImageCaption;
    }
}

My Partial

<?php

namespace App\Fields;

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

class blockImage extends Field
{
    /**
     * The field group.
     *
     * @return array
     */
    public function fields()
    {
        $blockImage = new FieldsBuilder('block_image');

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

        $blockImage
            ->addFields($this->get(blockImageCaption::class));

        return $blockImage->build();
    }
}

Few things:

  • I suggest capitalizing the casing on your field classes (blockImageBlockImage, blockImageCaptionBlockImageCaption)
  • You need to include the partial’s namespace in your Field:
    use App\Fields\Partials\BlockImageCaption;
2 Likes

Ow that was it! Totally read over the fact that the namespace needs to be included… thanks for being so patient.

Kind regards,

Tim