Skip to content

Commit 19d9ce3

Browse files
committed
Merge branch 'release/0.1.8'
2 parents 45a29bd + b681d77 commit 19d9ce3

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

readme.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Corcel ACF Plugin
22

3-
[![Travis](https://travis-ci.org/jgrossi/corcel.svg?branch=master)](https://travis-ci.org/corcel/acf?branch=master)
3+
[![Travis](https://travis-ci.org/corcel/acf.svg?branch=master)](https://travis-ci.org/corcel/acf?branch=master)
44
[![Packagist](https://img.shields.io/packagist/v/corcel/acf.svg)](https://github.com/corcel/acf/releases)
55
[![Packagist](https://img.shields.io/packagist/dt/corcel/acf.svg)](https://packagist.org/packages/corcel/acf)
66

@@ -22,7 +22,7 @@ For more information about how Corcel works please visit [the repository](http:/
2222
# Installation
2323

2424
To install the ACF plugin for Corcel is easy:
25-
25+
2626
```
2727
composer require corcel/acf
2828
```
@@ -41,16 +41,16 @@ echo $post->acf->url; // returns the url custom field created using ACF
4141
## Performance
4242

4343
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:
44-
44+
4545
```php
4646
// Extra queries way
4747
echo $post->acf->author_username; // it's a User field
48-
48+
4949
// Without extra queries
5050
echo $post->acf->user('author_username');
5151
```
52-
53-
> 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.
52+
53+
> 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.
5454
5555
## The Idea
5656

@@ -65,11 +65,11 @@ This plugin works with a basic logic inside `Corcel\Acf\Field\BasicField` abstra
6565
## What is Missing
6666

6767
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!).
68-
68+
6969
- Create more unit tests for `Repeater` field;
70-
- Implement the `Flexible Content` field with unit tests;
70+
- Implement the `Flexible Content` field with unit tests (done!);
7171
- Improve performance. Currently the plugin makes one SQL query for each field. This goal is to improve that using `whereIn()` clauses.
72-
72+
7373
Some fields are still missing (check table below and contribute).
7474

7575
## Fields
@@ -128,4 +128,4 @@ You should import the `database.sql` file to a database inside your local enviro
128128
129129
# Licence
130130

131-
[MIT License](http://jgrossi.mit-license.org/) © Junior Grossi
131+
[MIT License](http://jgrossi.mit-license.org/) © Junior Grossi

src/AdvancedCustomFields.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ public function __call($name, $arguments)
5555

5656
$field = FieldFactory::make($arguments[0], $this->post, snake_case($name));
5757

58-
return $field->get();
58+
return $field ? $field->get() : null;
5959
}
6060
}

src/Field/FlexibleContent.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ protected function fetchFields($fieldName, Builder $builder)
9797
$id = $this->retrieveIdFromFieldName($meta->meta_key, $fieldName);
9898

9999
$name = $this->retrieveFieldName($meta->meta_key, $fieldName, $id);
100-
$field = FieldFactory::make($meta->meta_key, $this->post->find($meta->post_id));
100+
101+
$post = $this->post->ID != $meta->post_id ? $this->post->find($meta->post_id) : $this->post;
102+
$field = FieldFactory::make($meta->meta_key, $post);
101103

102104
if (!array_key_exists($id, $blocks)) {
103105
continue;

src/Field/Repeater.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ protected function fetchFields($fieldName, Builder $builder)
9797
foreach ($builder->get() as $meta) {
9898
$id = $this->retrieveIdFromFieldName($meta->meta_key, $fieldName);
9999
$name = $this->retrieveFieldName($meta->meta_key, $fieldName, $id);
100-
$field = FieldFactory::make($meta->meta_key, $this->post->find($meta->post_id));
100+
101+
$post = $this->post->ID != $meta->post_id ? $this->post->find($meta->post_id) : $this->post;
102+
$field = FieldFactory::make($meta->meta_key, $post);
103+
101104
$fields[$id][$name] = $field->get();
102105
}
103106

0 commit comments

Comments
 (0)