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

Closed

Conversation

njbarrett
Copy link

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.

@@ -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

@JuiceboxCreative JuiceboxCreative closed this by deleting the head repository Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants