StoutLogic / acf-builder

An Advanced Custom Field Configuration Builder
GNU General Public License v2.0
795 stars 62 forks source link

Clone? Extension plugins? #37

Open alicam opened 7 years ago

alicam commented 7 years ago

Great little bit of code you have here!

Two questions, more than issues...

  1. ACF Pro now has the "Clone" type and it's pretty awesome. Is there some logic to use commandeering this for "object inheritance", do you think? Or is your approach enough? I just assume using the default ACF approach is typically wise??

  2. I use ACF Pro extensions for things like choosing a GravityForm, or a registered menu for insertion on the page somehow... Would it be difficult to have a simple extension framework for acf-builder that would allow me to use these, or even better, have some convention where they're auto-discovered and usable immediately??!

Many thanks!

-Alister Cameron

stevep commented 7 years ago

@alicam:

  1. I read in the ACF change log about the clone type, it was released after I initially released this library. It does seem handy if you use the UI to build fields. It solves one of the bigger issues of reuse. I've not experimented with it at all, or have looked at the source code, so I can't say for sure, but I assume it works similarly in that from the clone field config it creates discrete fields in memory. My personal belief is that ACF Builder is more flexible because you have a handle to the field config, in code, to do whatever you want. Also it can live versioned in your source code repository.

  2. You should be able to use any ACF plugin field out of the box. You can use the generic addField function, where the second parameter is the field type. All existing add field functions utilize it. Perhaps a good new feature would be to use method missing __call function on the FieldsBuilder class to look for function calls that begin with "add" and call the addField function with a snaked-cased version of anything after the word "add" in the function.

Example:

$fieldBuilder
   ->addGravityFormsField('my_field_name');

Would automatically call:

$fieldBuilder
    ->addField('my_field_name', 'gravity_forms_field')

Probably would be useful. Until then you can call the addField('gravity_forms_field') manually, and pass any arguments you need as the third parameter.

Log1x commented 6 years ago

Going to bump this for #2 -- this would be the most beneficial feature at this point in my opinion. I use a lot of third party extensions and ->addField() can get a little intense looking.

Auto detection -> camalCase would be cool, but I'd personally love a way to create "macros" so to speak.

$macro = new MacroBuilder('column');
$macro->create('column', ['column-type' => '1_2']);

Would perhaps create ->addColumn($name, 'column', $args) with column-type defaulting to 1_2 in the args for use with ACF Columns.

This would allow the creation of additional helpers such as in this case, I'd create a ->addEndColumn() which would default column-type to 1_1 which is the "reset".

stevep commented 6 years ago

Been thinking about the the addField, the easy thing to do would be to hook into __call and if it detected addFieldType('name'), it would convert that to addField('name', 'field_type').

Other longer term option might be for a rewrite where instead of addText, addWysiywg just being syntactic sugar for addField('name', 'text) they become their own builders (TextFieldBuilder, WysiwygBuilder) that register with the main builder.

Also it has been on my mind to add a field width API. I hate adding ['wrapper' => ['width' => '50%']] to all my fields too.

cheestudio commented 3 years ago

@stevep very old topic, but curious what the current status is on using ACF Clone fields?

chrillep commented 11 months ago

+1