Skip to content

Upgrade from 1.13 to 1.14.x breaks ACF fields  #62

@visahakkarainen

Description

@visahakkarainen

When upgrading to 1.14.x from 1.13 I noticed that conditional logic and format_value method stopped working. There might even be more things that have broken when I upgraded but those are the two things I noticed.

My conditional logic on my project looks like this:

        // Radio buttons
        $product_type = ( new Field\Radio( __( 'Type', 'the-dustpress-theme' ) ) )
            ->set_key( $key . '_product_card_type' )
            ->set_name( 'product_card_type' )
            ->add_choice( __( 'Product', 'the-dustpress-theme' ), 'product' )
            ->add_choice( __( 'Category', 'the-dustpress-theme' ), 'category' )
            ->set_required();
        $this->add_field_before( $product_type, 'list' );

        // Conditional logic based on radio buttons
        $cond_logic_product = ( new ConditionalLogicGroup() )
            ->add_rule( $product_type, '==', 'product' );

        $cond_logic_category = ( new ConditionalLogicGroup() )
            ->add_rule( $product_type, '==', 'category' );

        // Get repeater field and add conditional logic for the whole card field area inside repeater
        $repeater = $this->get_field( 'list' );
        $card_automatic = $repeater->get_field( 'card_automatic' );
        $card_automatic->add_conditional_logic( $cond_logic_product );

        // New cards field used when adding terms
        $autom_card_args = [
            'use_card_style' => $this->use_card_style,
            'card_taxonomy'  => $this->card_taxonomy,
            'use_taxonomy'   => $this->use_taxonomy,
        ];

        $category_cards = new CardAutomatic( $this->card_label, $key . '_prod_term', 'prod_term', $autom_card_args );
        $category_cards->set_wrapper_classes( 'geniem-acf-inline' )
            ->add_conditional_logic( $cond_logic_category );
        $repeater->add_field( $category_cards );

format_value stopped working when code looked like this:

        // Video embed url
        $url = ( new Field\Url( __( 'Url of the video as a whole (Youtube or Vimeo)', 'the-dustpress- 
        theme' ) ) )
            ->set_key( $this->key . '_url' )
            ->set_name( 'url' )
            ->set_required();
        $this->add_field( $url );

        $this->format_value( [ $this, 'format_video_url' ] );

I had to move format_value to $url variable in order to get it to work properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions