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

Fix problem with empty acf taxonomy relationship field loading all terms instead of none. #2960

Merged
merged 1 commit into from May 14, 2024

Conversation

rubas
Copy link
Contributor

@rubas rubas commented Apr 2, 2024

Problem

The function transform_taxonomy will load ALL terms with Timber::get_terms([]), if there is no value stored in an ACF relationship field.

  public static function transform_taxonomy($value, $id, $field)
  {
    if ('select' === $field['field_type'] || 'radio' === $field['field_type']) {
      return Timber::get_term((int) $value);
    }

    return Timber::get_terms((array) $value);
  }

Solution

Check for empty and return false.

Alternative

Return [] instead of false.

@Levdbas
Copy link
Member

Levdbas commented Apr 26, 2024

Hi @rubas , nice find!

@Levdbas Levdbas added this to the 2.2.0 milestone May 10, 2024
@rubas
Copy link
Contributor Author

rubas commented May 10, 2024

It would be nice if you could create a test for this as well. Are you in for that?

Sorry, I was pretty busy (and holidays) lately. I haven't look at your test setup and it will be a few weeks (June?) before I find the time to do so.

I guess I'll do with the next PR ;-)

@Levdbas
Copy link
Member

Levdbas commented May 10, 2024

do with the next PR ;-)

I took a more in depth dive in your PR and I think we can do without tests I think. Or else we would need to make tests for all three transform methods to check what the results are with an empty field.

@gchtr gchtr merged commit f95b82a into timber:2.x May 14, 2024
28 checks passed
@gchtr
Copy link
Member

gchtr commented May 14, 2024

Thanks for the fix, @rubas! 🙌

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.

None yet

3 participants