ACF\Pro\Datastore

Check_Screen::attach_store_datapublicACF 6.8.1

Attaches datastore data for newly-loaded field groups to the response.

Method of the class: Check_Screen{}

No Hooks.

Returns

Array.

Usage

$Check_Screen = new Check_Screen();
$Check_Screen->attach_store_data( $response, $field_groups, $args );
$response(array) (required)
The check_screen response array.
$field_groups(array) (required)
The field groups returned for this screen.
$args(array) (required)
The check_screen request args (post_id, screen, exists, ...).

Changelog

Since 6.8.1 Introduced.

Check_Screen::attach_store_data() code ACF 6.8.8

public function attach_store_data( $response, $field_groups, $args ) {
	if ( ! acf_is_using_datastore() ) {
		return $response;
	}

	$store_data = array(
		'context'     => array(
			'postId'   => (int) $args['post_id'],
			'postType' => get_post_type( (int) $args['post_id'] ) ?: '',
		),
		'fields'      => array(),
		'values'      => array(),
		'fieldGroups' => array(),
	);

	$localization = acf_get_instance( 'ACF\\Pro\\Datastore\\Localization' );
	$exists       = isset( $args['exists'] ) ? (array) $args['exists'] : array();

	foreach ( (array) $field_groups as $field_group ) {
		// Only collect data for field groups not already on the page.
		if ( in_array( $field_group['key'], $exists, true ) ) {
			continue;
		}

		$fields = acf_get_fields( $field_group );
		if ( ! $fields ) {
			continue;
		}

		$localization->collect_field_data( $fields, $args['post_id'], $field_group['key'], $store_data );

		$store_data['fieldGroups'][] = array(
			'key'                   => $field_group['key'],
			'title'                 => acf_esc_html( acf_get_field_group_title( $field_group ) ),
			'position'              => $field_group['position'],
			'style'                 => $field_group['style'],
			'label_placement'       => $field_group['label_placement'],
			'instruction_placement' => $field_group['instruction_placement'],
			'edit_url'              => esc_url( acf_get_field_group_edit_link( $field_group['ID'] ) ),
		);
	}

	if ( ! empty( $store_data['fields'] ) ) {
		$response['storeData'] = $store_data;
	}

	return $response;
}