2017 © Pedro Peláez
 

library acf-builder

An Advanced Custom Field Configuration Builder

image

stoutlogic/acf-builder

An Advanced Custom Field Configuration Builder

  • Wednesday, August 1, 2018
  • by stoutlogic
  • Repository
  • 17 Watchers
  • 135 Stars
  • 3,996 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 10 Forks
  • 11 Open issues
  • 15 Versions
  • 33 % Grown

The README.md

ACF Builder

Create configuration arrays for Advanced Custom Fields Pro using the builder pattern and a fluent API., (*1)

Quickly create, register, and reuse ACF configurations, and keep them in your source code repository. To read more about registering ACF fields via php consult https://www.advancedcustomfields.com/resources/register-fields-via-php/, (*2)

Latest Stable Version Build Status Scrutinizer Code Quality Join the chat at https://gitter.im/StoutLogic/acf-builder, (*3)

Simple Example

$banner = new StoutLogic\AcfBuilder\FieldsBuilder('banner');
$banner
    ->addText('title')
    ->addWysiwyg('content')
    ->addImage('background_image')
    ->setLocation('post_type', '==', 'page')
        ->or('post_type', '==', 'post');

add_action('acf/init', function() use ($banner) {
   acf_add_local_field_group($banner->build());
});

$banner->build(); will return:, (*4)

[
    'key' => 'group_banner',
    'title' => 'Banner',
    'fields' => [
        [
            'key' => 'field_title',
            'name' => 'title',
            'label' => 'Title',
            'type' => 'text'
        ],
        [
            'key' => 'field_content',
            'name' => 'content',
            'label' => 'Content',
            'type' => 'wysiwyg'
        ],
        [
            'key' => 'field_background_image',
            'name' => 'background_image',
            'label' => 'Background Image',
            'type' => 'image'
        ],
    ],
    'location' => [
        [
            [
                'param' => 'post_type',
                'operator' => '==',
                'value' => 'page'
            ]
        ],
        [
            [
                'param' => 'post_type',
                'operator' => '==',
                'value' => 'post'
            ]
        ]
    ]
]

As you can see it saves you a lot of typing and is less error-prone. But brevity and correctness isn't the only benefit, you can reuse field configurations in multiple places. For example, a group of fields used for backgrounds:, (*5)

Reuse Example


use StoutLogic\AcfBuilder\FieldsBuilder; $background = new FieldsBuilder('background'); $background ->addTab('Background') ->addImage('background_image') ->addTrueFalse('fixed') ->instructions("Check to add a parallax effect where the background image doesn't move when scrolling") ->addColorPicker('background_color'); $banner = new FieldsBuilder('banner'); $banner ->addTab('Content') ->addText('title') ->addWysiwyg('content') ->addFields($background) ->setLocation('post_type', '==', 'page'); $section = new FieldsBuilder('section'); $section ->addTab('Content') ->addText('section_title') ->addRepeater('columns', ['min' => 1, 'layout' => 'block']) ->addTab('Content') ->addText('title') ->addWysiwyg('content') ->addFields($background) ->endRepeater() ->addFields($background) ->setLocation('post_type', '==', 'page');

Here a background field group is created, and then used in two other field groups, including twice in the section field group. This can really DRY up your code and keep your admin UI consistent. If you wanted to add a light/dark field for the text color field based on the background used, it would just need to be added in one spot and used everywhere., (*6)

Install

Use composer to install:, (*7)

composer require stoutlogic/acf-builder

If your project isn't using composer, you can require the autoload.php file., (*8)

Tests

To run the tests you can manually run, (*9)

vendor/bin/phpunit

or you can use the built in gulp task to run it on file change, (*10)

npm install
gulp

Requirements

PHP 5.4 through 7.2 supported but automated tests cannot be run anymore so it might stop working at some point., (*11)

= 7.4, 8 Tested, (*12)

Documentation

See the wiki for more thorough documentation. The documentation has its own repository and accepts pull requests for contributions. Any merges to master will get synced with the wiki here under the main project., (*13)

The Versions

01/08 2018

dev-develop

dev-develop

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Steve Pfisterer

01/08 2018

dev-master

9999999-dev

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Steve Pfisterer

21/05 2018

1.6.1

1.6.1.0

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Steve Pfisterer

02/12 2017

1.6.0

1.6.0.0

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Steve Pfisterer

19/09 2017

1.5.0

1.5.0.0

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Steve Pfisterer

06/08 2017

v1.4.0

1.4.0.0

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Steve Pfisterer

10/01 2017

1.3.0

1.3.0.0

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Steve Pfisterer

23/11 2016

1.2.0

1.2.0.0

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Steve Pfisterer

27/06 2016

v1.1.1

1.1.1.0

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.5.0

 

The Development Requires

by Steve Pfisterer

18/06 2016

v1.1.0

1.1.0.0

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.5.0

 

The Development Requires

by Steve Pfisterer

13/06 2016

v1.0.4

1.0.4.0

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.5.0

 

The Development Requires

by Steve Pfisterer

07/06 2016

v1.0.3

1.0.3.0

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.5.0

 

The Development Requires

by Steve Pfisterer

19/05 2016

v1.0.2

1.0.2.0

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

by Steve Pfisterer

16/05 2016

v1.0.1

1.0.1.0

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

by Steve Pfisterer

16/05 2016

v1.0.0

1.0.0.0

An Advanced Custom Field Configuration Builder

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

by Steve Pfisterer