GithubHelp home page GithubHelp logo

samrap / acf-fluent Goto Github PK

View Code? Open in Web Editor NEW
285.0 13.0 14.0 78 KB

✒️ A fluent interface for the Advanced Custom Fields WordPress plugin

License: MIT License

PHP 100.00%
acf acf-field advanced-custom-fields wordpress fluent fluent-interface

acf-fluent's People

Contributors

catgofire avatar samrap avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

acf-fluent's Issues

Support for "macros"

The ability to define something like this...

Acf::macro('imageArray', function ($builder) {
    return $builder
        ->expect('array')
        ->default([
            'url' => 'default.jpg',
            'alt' => 'Default Image',
        ]);
});

...and then call that "macro" from anywhere else in your code...

Acf::field('image')->imageArray()->get();

...might be a good way to shorten complex ACF queries especially when using the same expectation logic throughout templates.

->shortcodes() can not be used with an array

With the introduction of Group fields, my template is getting pretty heavy with values being inside of the group's array.

I was curious if you thought about any fluent, elegant way we could retrieve values, as well as process their shortcodes without assigning it to a variable and running do_shortcode() on it?

At the moment, I have to do the following:

$header = Acf::field('header')->get();
return do_shortcode($header['subtitle']);

It'd be pretty nice to be able to retrieve a specific keys value from the array and process our escapes, shortcodes, and possibly even a default right from the ->get()-go.

Something like Acf::field('header')->key('subtitle')->shortcodes()->get() ?

I'm sure it can be done in a much more sane syntax, the above is merely a pseudo-example.

Also, have you brainstormed on how we could have_rows(); the_row(); using acf-fluent? It'd be absolutely great if I can ditch ACF's functions all together. They are just... ugly. I ignore them in most cases using Blade directives with Sage 9, but I'd still much rather using acf-fluent for all of my ACF calls.

I'm sure you've thought about the above and it might just not be deemed sane-- but I thought I'd bring it up nonetheless.

Thanks a lot for acf-fluent. Using it with acf-builder is really great. 😃

Shortcodes method is not fluent

The builder shortcodes method does not return a builder instance.

The Builder's fluent interface should always return $this for every builder method. The shortcodes method was missing this and causing a runtime error. All tests should be updated to ensure $this is returned.

Cache internal classes where appropriate.

The package creates new instances of the following objects on every call:

  • Builder
  • Runner
  • Behavior (Field or SubField)

That means that 3 objects are created for every ACF call. Where appropriate, these classes should be cached and reused. The Builder acts as a container for the "queries", so it is not safe to cache this object. But the Runner and the behaviors should absolutely be instantiated no more than once.

A cache container should be created to store instances of each cacheable object to reduce the amount of resources used.

unexpected 'default' (T_DEFAULT), expecting identifier (T_STRING)

I have installed acf-fluent by running the suggested command in my Wordpress website's theme directory:

composer require samrap/acf-fluent

I then included my composer dependencies by requiring the vendor/autoload.php.

After doing the above and attempting to replicate the following example:

$heading = Acf::field('heading') ->default(get_the_title()) ->escape() ->get();

I receive the error:

Parse error: syntax error, unexpected 'default' (T_DEFAULT), expecting identifier (T_STRING) in {path_to_my_theme}/vendor/samrap/acf-fluent/src/Fluent/Builder.php on line 124

I don't think this should have an impact on the issue, but I am using Wordpress 4.7.3, the latest version of ACF Pro and the theme I am developing is based on the Roots Sage base theme (https://github.com/roots/sage).

Perhaps I am doing something wrong, but I have tried including acf-fluent a few different ways and seem to get the same error every time.

I look forward to using your interface in the future, and thanks in advance!

Consider changing namespace

The Acf namespace does not properly reflect the package. Consider renaming this to a more descriptive namespace, or simply using Samrap\Acf.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.