Automattic\WooCommerce\Blocks\BlockTypes

MiniCart::enqueue_data()protectedWC 1.0

Extra data passed through from server to client for block.

Method of the class: MiniCart{}

Hooks from the method

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->enqueue_data( $attributes );
$attributes(array)
Any attributes that currently are available from the block. Note, this will be empty in the editor context when the block is not in the post content on editor load.
Default: []

MiniCart::enqueue_data() code WC 9.0.1

protected function enqueue_data( array $attributes = [] ) {
	if ( is_cart() || is_checkout() ) {
		return;
	}

	parent::enqueue_data( $attributes );

	// Hydrate the following data depending on admin or frontend context.
	if ( ! is_admin() && ! WC()->is_rest_api_request() ) {
		$label_info = $this->get_tax_label();

		$this->tax_label                         = $label_info['tax_label'];
		$this->display_cart_prices_including_tax = $label_info['display_cart_prices_including_tax'];

		$this->asset_data_registry->add(
			'taxLabel',
			$this->tax_label
		);
	}

	$this->asset_data_registry->add(
		'displayCartPricesIncludingTax',
		$this->display_cart_prices_including_tax
	);

	$template_part_edit_uri = '';

	if (
		current_user_can( 'edit_theme_options' ) &&
		( wc_current_theme_is_fse_theme() || current_theme_supports( 'block-template-parts' ) )
	) {
		$theme_slug = BlockTemplateUtils::theme_has_template_part( 'mini-cart' ) ? wp_get_theme()->get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG;

		if ( version_compare( get_bloginfo( 'version' ), '5.9', '<' ) ) {
			$site_editor_uri = add_query_arg(
				array( 'page' => 'gutenberg-edit-site' ),
				admin_url( 'themes.php' )
			);
		} else {
			$site_editor_uri = add_query_arg(
				array(
					'canvas' => 'edit',
					'path'   => '/template-parts/single',
				),
				admin_url( 'site-editor.php' )
			);
		}

		$template_part_edit_uri = esc_url_raw(
			add_query_arg(
				array(
					'postId'   => sprintf( '%s//%s', $theme_slug, 'mini-cart' ),
					'postType' => 'wp_template_part',
				),
				$site_editor_uri
			)
		);
	}

	$this->asset_data_registry->add(
		'templatePartEditUri',
		$template_part_edit_uri
	);

	/**
	 * Fires after cart block data is registered.
	 *
	 * @since 5.8.0
	 */
	do_action( 'woocommerce_blocks_cart_enqueue_data' );
}