-
Notifications
You must be signed in to change notification settings - Fork 95
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
base: develop
Are you sure you want to change the base?
Conversation
@@ -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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
If you use the clone field type (fairly new acf type that clones another field) then you get an error:
Call to a member function get() on null
ACF stores clone fields as {fieldkey}_{clonedfieldkey} e.g
field_58d217c0bbeef_field_58cb8919c2607
so we can extract the parent's field type instead and everything works as expected.