Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

ACF Field Groups

Harry Wiseman edited this page Jan 23, 2019 · 2 revisions

Nemesis provides helper functions to create custom Field Groups to be used either with Blocks or just as normal ACF groups.

Note: All examples below are for use when adding new blocks

Testimonial example

When adding fields for the Testimonial block you first need to create a class for this located in classes/ACF/FieldGroups you will need to extend the BaseFields class provided by Nemesis - this will then give you access to all the different field types you need.

The documentation for adding Field Groups in PHP can be found here - the only difference when adding the group to a block is this section:

'location' => [
    [
        [
            'param' => 'block',
            'operator' => '==',
            'value' => 'acf/testimonial',
        ]
    ]
]

Where the location is set to block and the value is set to acf/{BLOCK_KEY}

<?php

namespace NanoSoup\Erebus\ACF\FieldGroups;

use NanoSoup\Nemesis\ACF\BaseFields;

/**
 * Class Testimonials
 * @package ACF\FieldGroups
 */
class Testimonials extends BaseFields
{
    /**
     *
     */
    public function init()
    {
        add_action('acf/init', [$this, 'registerFieldGroup']);
    }

    /**
     *
     */
    public function registerFieldGroup()
    {
        acf_add_local_field_group([
            'key' => 'group_block_testimonial',
            'title' => 'Block: Testimonial',
            'fields' => [
                $this->textarea('block_testimonial', 'Testimonial'),
                $this->text('block_testimonial', 'Author'),
                $this->image('block_testimonial', 'Avatar')
            ],
            'location' => [
                [
                    [
                        'param' => 'block',
                        'operator' => '==',
                        'value' => 'acf/testimonial',
                    ]
                ]
            ],
            'menu_order' => 0,
            'position' => 'normal',
            'style' => 'default',
            'label_placement' => 'top',
            'instruction_placement' => 'label',
            'hide_on_screen' => '',
            'active' => 1,
            'description' => '',
        ]);
    }
}

Clone this wiki locally