Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Acf Builder Laravel Package

stoutlogic/acf-builder

Fluent builder for Advanced Custom Fields Pro (ACF) field groups. Define fields and locations in PHP, reuse configs, and generate ACF’s registration arrays with less boilerplate. Ideal for keeping ACF setup in version control.

View on GitHub
Deep Wiki
Context7
v1.12.0

A frequent requested feature was the ability to modify and remove nested fields. This is now possible with adding the getField method to the GroupBuilder and getLayout to the FlexibleContentBuilder. Also introduced is a short hand so you don't have to chain getField calls. Using the -> delimiter you can directly reach the field you're right to modify or remove.

Example:

$builder->removeField('sections->hero->sub_title');

There was discussion of using a . dot delimiter instead for the short hand, but I decided to use the arrow in case people had used a . in their existing field names. I didn't want them to experience unintended consequences. When releasing a major version with breaking changes we will revisit this possibility.

Check out the docs for it here: https://github.com/StoutLogic/acf-builder/wiki/modifying-fields#modifying-nested-fields

Thanks @Androlax2 @voyou-sbeaulieu @marcelo2605 for your contributions and patience

1.11.1

Merged in some PRs: #133 and #137

Thanks @titouanmathis and @davddo

1.11.0

You can now write conditionals that reference fields not on the same level. [Issue: #52]

You can either just reference the name of the parent field:

$builder = new \StoutLogic\AcfBuilder\FlexibleContentBuilder('sections');
$builder
  ->addLayout('hero')
  ->addSelect('hero_type')
  ->addChoices('fullscreen', 'standard')
  ->addImage( 'hero_image' )
  ->addWysiwyg( 'hero_text' )
  ->addRepeater('cta')
    ->addSelect('link_type')
    ->addChoices('internal', 'external', 'text')
    ->addTrueFalse('cta_animated')
      ->conditional('hero_type', '==', 'fullscreen');

Or you can set a custom key

$builder = new \StoutLogic\AcfBuilder\FlexibleContentBuilder('sections');
$builder
  ->addLayout('hero')
  ->addSelect('hero_type')
  ->addChoices('fullscreen', 'standard')
    ->setCustomKey('my_custom_key')
  ->addImage( 'hero_image' )
  ->addWysiwyg( 'hero_text' )
  ->addRepeater('cta')
    ->addSelect('link_type')
    ->addChoices('internal', 'external', 'text')
    ->addTrueFalse('cta_animated')
      ->conditional('my_custom_key', '==', 'fullscreen');

This shouldn't break backwards compatibility, I've tested it on my professional projects. But if you do run into issues, let me know ASAP.

Other additions include:

  • #130 Fix Intelephense's Undefined method
  • Setup testing via GitHub actions for php versions 5.4 - 7.4. The version of PHP unit being used isn't supported for PHP 8.0 so it is untested. If you run into any issues in the wild, while testing on 8.0, let me know.
1.10.0

Add support for doctrine/inflector ^2.0 and some code cleanup, while maintaining backwards compatibility with Add support for doctrine/inflector ^1.1 and older versions of PHP

Thanks @Log1x !

1.9.0

Allows you to use ->setLabel('My Custom Label') on a FieldBuilder. Thanks @Log1x and sorry for the delay.

1.8.1

ACF Builder relies on "doctrine/inflector": "^1.1", "doctrine/instantiator": "^1.0"

And now will allow newer 1.x versions to be installed along site ACF Builder. Thanks @guix77 !!

1.8.0

@aprokopenko has graciously added function calls to make setting field width, class, id and attributes much easier.

$builder = new FieldsBuilder('Slider')
$builder
    ->addText( 'slider_title' )
        ->setWidth( '50%' )
        ->setSelector( '#my-id.my-class' )
        ->setAttr( 'data-custom_attr', 'thisisattr' );

No more need to manually set the wrapper array as attributes to a new field.

1.7.2
1.7.1
1.7.0

You can use $fieldsBuilder->addButtonGroup like you would select or radio buttons. See ACF documentation for more information about Button Groups

Thanks @Log1x for the help!

1.6.1

Fixed issues #58 and #59

1.6.0

Added the new ACF Accordion field. Must be using ACF 5.6.6 to use it.

It works just like Tab field but includes two additional methods setOpen() and setMultiExpand(). true or false can be passed as a parameter, true is default.

$fieldgroup = new FieldsBuilder('group');
$fieldgroup
  ->addAccordion('content')
    ->setOpen()
    ->addWysiwyg('content')
  ->addAccordion('background')
    ->addImage('background_image')
    ->addColorPicker('background_color');
1.5.0

Updates:

Features

  • Added addRange method

Bug Fixes

  • Fix some potential issues with modifyField
  • Change modifyField documentation to explicitly say the passed closure needs to return a FieldsBuilder
  • Make PHP 7.2 compatible
  • Maintain PHP 5.4 compatibility by specifying older versions of dependencies
v1.4.0

Add new ACF fields addLink and addGroup. A group is treated just like a repeater, but instead of an endRepeater function, there is an endGroup function.

I'm releasing this before a refactor, which the code needs, because I wanted to get the functionality out there for everyone. I'm not happy with all of the inheritance, and I'm not longer happy with the confusing names FieldsBuilder vs FieldBuilder vs GroupBuilder Also I would like to use less magic methods if possible. Perhaps in a 2.0 release.

1.3.0
  • Add Google Map field function #25
  • Fix a bug regarding conditional logic and #26
1.2.0

Lots of internal changes, uses an array FieldBuilder objects to story field configs instead of storing field group's field config in a simple array.

Other changes:

  • addgetRootContext to get the top level parentContext
  • Make the fieldsBuilder in a RepeaterBuilder protected so sub classes can access it
  • Add getGroupConfig function to FieldsBuilder
  • Use Doctrine\Inflector to handle singularizing plural words on buttons
  • Add support for a Repeater collapsed attribute
  • Expose a fieldExists method to FieldsBuilder

Bug fixes:

  • Fix button label setting for repeater and flexible content
  • rename addPostLink to addPageLink on FieldsBuilder
v1.1.1

Moved tests to autoload-dev so they aren't included in production. Issue #18 Updated composer dependencies.

v1.1.0

Modifying and Removing Fields Added is the ability to modify, insert and remove fields from a FieldsBuilder. See the Modifying Fields page in the wiki for more information. Issue #12

Added addTimePicker and addDateTimePicker function ACF 5.3.9 added these two new fields Issue #13

v1.0.4

Fixes #8 #11

v1.0.3

Resolves issues #2 and #6

Fixes the setLocation bug. When setLocation is called on a builder, it will call it on the parent builder context if one exists.

To use the library without composer, simply require the included autoload.php file.

v1.0.2

'and' and 'or' are reserved keywords in PHP. Therefore PHP gets angry when you try to use them as method names. In testing it worked fine but in the real world they did not. They are now allowed via __call, and are aliases for andCondition and orCondition methods.

v1.0.1

Fix default keyword issue

v1.0.0
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope