Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Clone Field #25

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Field/BasicField.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ public function fetchFieldKey($fieldName)
*/
public function fetchFieldType($fieldKey)
{
// Check if this a clone field. If it is, return the field type of its clone.
$fieldKeyIds = explode('_', $fieldKey);
if (count($fieldKeyIds) == 4) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @njbarrett how are you considering 4 tokens here? If I have a field called first_name? Does it still work?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well the field name wont matter here, as this function gets the field type using the keys which are always field_{somehexvalue} e.g field_349efabab23 so the execution path is quite predictable

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually you might be right, i forgot you can name the field keys too. May need to come up with another way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a regex is better here. Something like /field_([A-Za-z0-9_-]+)_foo_bar/. Whenever you can please take a look on this. Don't worry about that. Thanks for contributing. JG

$fieldKey = 'field_' . $fieldKeyIds[3];
}

$post = $this->post->orWhere(function ($query) use ($fieldKey) {
$query->where('post_name', $fieldKey);
$query->where('post_type', 'acf-field');
Expand Down