From 3536234088d4d97afada484d20c6dc316ddf79d3 Mon Sep 17 00:00:00 2001 From: Naeem Date: Sun, 21 Jan 2018 12:14:39 +0400 Subject: [PATCH 1/3] Google Map field Google map field included which will return array with index 'address', 'lat', 'lng' --- readme.md | 3 +-- src/Field/GoogleMap.php | 34 ++++++++++++++++++++++++++++++++++ src/FieldFactory.php | 3 +++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/Field/GoogleMap.php diff --git a/readme.md b/readme.md index d718b9f..2bde44c 100644 --- a/readme.md +++ b/readme.md @@ -70,7 +70,6 @@ First we should create the fields classes and the test cases. After we have to s - 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 @@ -96,7 +95,7 @@ First we should create the fields classes and the test cases. After we have to s | Relationship | ok | [@jgrossi](http://github.com/jgrossi) | `Corcel\Post` or `Collection` of `Post` | | Taxonomy | ok | [@jgrossi](http://github.com/jgrossi) | `Corcel\Term` or `Collection` of `Term` | | User | ok | [@jgrossi](http://github.com/jgrossi) | `Corcel\User` | -| Google Map | missing | | +| Google Map | ok | [@naeemz](http://github.com/naeemz) | `array` | | Date Picker | ok | [@jgrossi](http://github.com/jgrossi) | `Carbon\Carbon` | | Date Time Picker | ok | [@jgrossi](http://github.com/jgrossi) | `Carbon\Carbon` | | Time Picker | ok | [@jgrossi](http://github.com/jgrossi) | `Carbon\Carbon` | diff --git a/src/Field/GoogleMap.php b/src/Field/GoogleMap.php new file mode 100644 index 0000000..ae387a9 --- /dev/null +++ b/src/Field/GoogleMap.php @@ -0,0 +1,34 @@ + + */ +class GoogleMap extends BasicField implements FieldInterface +{ + /** + * @var Array + */ + protected $cords; + + /** + * @param string $fieldName + */ + public function process($fieldName) + { + $this->cords = $this->fetchValue($fieldName); + } + + /** + * @return Array + */ + public function get() + { + return $this->cords; + } +} diff --git a/src/FieldFactory.php b/src/FieldFactory.php index 13d881f..53caae5 100644 --- a/src/FieldFactory.php +++ b/src/FieldFactory.php @@ -106,6 +106,9 @@ public static function make($name, Model $post, $type = null) break; case 'flexible_content': $field = new FlexibleContent($post); + break; + case 'google_map': + $field = new GoogleMap($post); break; default: return null; } From 2b2f4c11390fd4002f2291204288a09bf2ab4ceb Mon Sep 17 00:00:00 2001 From: Naeem Date: Tue, 17 Apr 2018 12:44:35 +0400 Subject: [PATCH 2/3] Update FieldFactory.php --- src/FieldFactory.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/FieldFactory.php b/src/FieldFactory.php index 53caae5..8516fef 100644 --- a/src/FieldFactory.php +++ b/src/FieldFactory.php @@ -6,6 +6,7 @@ use Corcel\Acf\Field\DateTime; use Corcel\Acf\Field\File; use Corcel\Acf\Field\Gallery; +use Corcel\Acf\Field\GoogleMap; use Corcel\Acf\Field\Image; use Corcel\Acf\Field\PageLink; use Corcel\Acf\Field\PostObject; @@ -107,7 +108,7 @@ public static function make($name, Model $post, $type = null) case 'flexible_content': $field = new FlexibleContent($post); break; - case 'google_map': + case 'google_map': $field = new GoogleMap($post); break; default: return null; From ef8ae7cf1e3f6499030b422c7cd0f7eac2647707 Mon Sep 17 00:00:00 2001 From: Naeem Date: Tue, 17 Apr 2018 12:50:21 +0400 Subject: [PATCH 3/3] Code Style --- src/FieldFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FieldFactory.php b/src/FieldFactory.php index 8516fef..0d616ce 100644 --- a/src/FieldFactory.php +++ b/src/FieldFactory.php @@ -108,7 +108,7 @@ public static function make($name, Model $post, $type = null) case 'flexible_content': $field = new FlexibleContent($post); break; - case 'google_map': + case 'google_map': $field = new GoogleMap($post); break; default: return null;