AdvancedCustomFields / AdvancedCustomFields/acf

ACF 5.8-Beta-4.1: Conditionally hidden sub field type image should (?) return empty value instead of false

Open
#165 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

I'm not 100% sure if my topic is a valid statement but let me show you a problem first.

The case:

Two subfields:

  • Image (type image)
  • Video (type url)

A video field should be shown only if there's no image (conditional logic).

The issue:

Steps:

When I insert a block and don't touch anything, the condition is satisfied (image is empty).
But when I insert anything to video field, save and reload, the video input disappears as the condition is no longer satisfied (image IS NOT empty!)

The code editor shows that there's data saved under the key:
"my-settings_image":false

Maybe it must be done this way and I should hide the video field on different condition?
Or this is a bug?

The code:

/**
 * Test ACF blocks in 5.8-beta4
 */

function my_acf_block_render_callback() {
	$settings = get_field( 'my-settings' );
	echo 'Image field stores:' . var_dump( $settings['image'] );
}

add_action( 'acf/init', 'my_acf_blocks_init' );
function my_acf_blocks_init() {
	/**
	 * Register block
	 */
	acf_register_block_type( array(
		'name'            => 'my',
		'title'           => __( 'My Test Block', 'my-acf' ),
		'description'     => __( 'A block for entering a link name and a custom URL.', 'my-acf' ),
		'render_callback' => 'my_acf_block_render_callback',
		'category'        => 'formatting',
		'icon'            => 'external',
		'keywords'        => array(),
		'supports'        => array( 'align' => false ),
		'mode'            => 'edit',
	) );

	/**
	 * Define block fields
	 */
	acf_add_local_field_group( array(
		'key' => "group_my",
		'title' => __( 'Block :: My Test Block', 'my-acf' ),
		'location' => array(
			array(
				array(
					'param' => 'block',
					'operator' => '==',
					'value' => 'acf/my',
				),
			),
		),
		'fields' => array(
			array(
				'key' => "field_my-settings",
				'label' => false,
				'name' => "my-settings",
				'type' => 'group',
				'layout' => 'block',
				'sub_fields' => array(
					/* Image */
					array(
						'key' => "field_my-settings-image",
						'label' => __( 'Image', 'sai-acf' ),
						'name' => 'image',
						'type' => 'image',
						'return_format' => 'id',
						'preview_size' => 'thumbnail',
					),
					/* Video */
					array(
						'key' => "field_my-settings-video",
						'label' => __( 'Video', 'sai-acf' ),
						'name' => 'video',
						'type' => 'url',
						'conditional_logic' => array(
							array(
								array(
									'field' => "field_my-settings-image",
									'operator' => '==empty',
								),
							),
						),
						'placeholder' => 'https://',
					),
				),
			), // EOF settings
		),
	) );
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PHP reproduction in the issue, focusing on the image subfield value and the conditional logic on the video subfield. Trace how an untouched image is saved and evaluated after reload; done means the behavior is documented or corrected so the conditional field follows the intended empty-image case.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.