From a25f4803abd676189d6498f2cf62089c2454a12b Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Wed, 15 Feb 2017 17:16:56 -0200 Subject: [PATCH 1/4] Fix Travis badge in readme file --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 825872f..cbe6fe6 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # Corcel ACF Plugin -[![Travis](https://travis-ci.org/jgrossi/corcel.svg?branch=master)](https://travis-ci.org/corcel/acf?branch=master) +[![Travis](https://travis-ci.org/corcel/acf.svg?branch=master)](https://travis-ci.org/corcel/acf?branch=master) [![Packagist](https://img.shields.io/packagist/v/corcel/acf.svg)](https://github.com/corcel/acf/releases) [![Packagist](https://img.shields.io/packagist/dt/corcel/acf.svg)](https://packagist.org/packages/corcel/acf) From e288e2870edd034b38c4bcb725f318a67bbc1520 Mon Sep 17 00:00:00 2001 From: Marco Boom Date: Fri, 24 Feb 2017 17:10:41 +0100 Subject: [PATCH 2/4] Prevent double queries in Repeater and Flexible Content --- src/Field/FlexibleContent.php | 4 +++- src/Field/Repeater.php | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Field/FlexibleContent.php b/src/Field/FlexibleContent.php index bb49b9b..b207f9c 100644 --- a/src/Field/FlexibleContent.php +++ b/src/Field/FlexibleContent.php @@ -97,7 +97,9 @@ protected function fetchFields($fieldName, Builder $builder) $id = $this->retrieveIdFromFieldName($meta->meta_key, $fieldName); $name = $this->retrieveFieldName($meta->meta_key, $fieldName, $id); - $field = FieldFactory::make($meta->meta_key, $this->post->find($meta->post_id)); + + $post = $this->post->ID != $meta->post_id ? $this->post->find($meta->post_id) : $this->post; + $field = FieldFactory::make($meta->meta_key, $post); if (!array_key_exists($id, $blocks)) { continue; diff --git a/src/Field/Repeater.php b/src/Field/Repeater.php index ec47626..0a2a459 100644 --- a/src/Field/Repeater.php +++ b/src/Field/Repeater.php @@ -97,7 +97,10 @@ protected function fetchFields($fieldName, Builder $builder) foreach ($builder->get() as $meta) { $id = $this->retrieveIdFromFieldName($meta->meta_key, $fieldName); $name = $this->retrieveFieldName($meta->meta_key, $fieldName, $id); - $field = FieldFactory::make($meta->meta_key, $this->post->find($meta->post_id)); + + $post = $this->post->ID != $meta->post_id ? $this->post->find($meta->post_id) : $this->post; + $field = FieldFactory::make($meta->meta_key, $post); + $fields[$id][$name] = $field->get(); } From e09270b432c3efb3e58d03b982a4013159492c56 Mon Sep 17 00:00:00 2001 From: Marco Boom Date: Fri, 24 Feb 2017 17:12:02 +0100 Subject: [PATCH 3/4] Prevent fatal error when field not exists and calling it by type --- src/AdvancedCustomFields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdvancedCustomFields.php b/src/AdvancedCustomFields.php index 9aad0d8..2801104 100644 --- a/src/AdvancedCustomFields.php +++ b/src/AdvancedCustomFields.php @@ -55,6 +55,6 @@ public function __call($name, $arguments) $field = FieldFactory::make($arguments[0], $this->post, snake_case($name)); - return $field->get(); + return $field ? $field->get() : null; } } From b681d7796947400a01e75b9e23536d77661ccfb4 Mon Sep 17 00:00:00 2001 From: Junior Grossi Date: Wed, 1 Mar 2017 09:53:25 -0300 Subject: [PATCH 4/4] Update readme --- readme.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/readme.md b/readme.md index cbe6fe6..d718b9f 100644 --- a/readme.md +++ b/readme.md @@ -22,7 +22,7 @@ For more information about how Corcel works please visit [the repository](http:/ # Installation To install the ACF plugin for Corcel is easy: - + ``` composer require corcel/acf ``` @@ -41,16 +41,16 @@ echo $post->acf->url; // returns the url custom field created using ACF ## Performance When using something like `$post->acf->url` the plugin has to make some extra SQL queries to get the field type according ACF approach. So we created another way to get that without making those extra queries. You have only the inform the plugin what is the post type, as a function: - + ```php // Extra queries way echo $post->acf->author_username; // it's a User field - + // Without extra queries echo $post->acf->user('author_username'); ``` - - > PS: The method names should be written in `camelCase()` format. So, for example, for the field type `date_picker` you should write `$post->acf->datePicker('fieldName')`. The plugin does the conversion from `camelCase` to `snake_case` for you. + + > PS: The method names should be written in `camelCase()` format. So, for example, for the field type `date_picker` you should write `$post->acf->datePicker('fieldName')`. The plugin does the conversion from `camelCase` to `snake_case` for you. ## The Idea @@ -65,11 +65,11 @@ This plugin works with a basic logic inside `Corcel\Acf\Field\BasicField` abstra ## What is Missing First we should create the fields classes and the test cases. After we have to setup how Corcel is going to work with the `corcel/acf` plugin, returning the custom field value in the format `$post->meta->field` or maybe `$post->acf->field` having different behavior (done!). - + - Create more unit tests for `Repeater` field; - - Implement the `Flexible Content` field with unit tests; + - Implement the `Flexible Content` field with unit tests (done!); - Improve performance. Currently the plugin makes one SQL query for each field. This goal is to improve that using `whereIn()` clauses. - + Some fields are still missing (check table below and contribute). ## Fields @@ -128,4 +128,4 @@ You should import the `database.sql` file to a database inside your local enviro # Licence -[MIT License](http://jgrossi.mit-license.org/) © Junior Grossi \ No newline at end of file +[MIT License](http://jgrossi.mit-license.org/) © Junior Grossi