Automattic\WooCommerce\Blocks\BlockTypes

MiniCart::enqueue_data()protectedWC 1.0

Extra data passed through from server to client for block.

{} Это метод класса: MiniCart{}

Хуки из метода

Возвращает

null. Ничего.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->enqueue_data( $attributes );
$attributes(массив)
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.
По умолчанию: []

Код MiniCart::enqueue_data() WC 6.9.4

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,
			''
		);

		$cart_payload = $this->get_cart_payload();

		$this->asset_data_registry->add(
			'cartTotals',
			isset( $cart_payload['totals'] ) ? $cart_payload['totals'] : null,
			null
		);

		$this->asset_data_registry->add(
			'cartItemsCount',
			isset( $cart_payload['items_count'] ) ? $cart_payload['items_count'] : null,
			null
		);
	}

	$script_data = $this->asset_api->get_script_data( 'build/mini-cart-component-frontend.js' );

	$num_dependencies = count( $script_data['dependencies'] );
	$wp_scripts       = wp_scripts();

	for ( $i = 0; $i < $num_dependencies; $i++ ) {
		$dependency = $script_data['dependencies'][ $i ];

		foreach ( $wp_scripts->registered as $script ) {
			if ( $script->handle === $dependency ) {
				$this->append_script_and_deps_src( $script );
				break;
			}
		}
	}

	$payment_method_registry = Package::container()->get( PaymentMethodRegistry::class );
	$payment_methods         = $payment_method_registry->get_all_active_payment_method_script_dependencies();

	foreach ( $payment_methods as $payment_method ) {
		$payment_method_script = $this->get_script_from_handle( $payment_method );

		if ( ! is_null( $payment_method_script ) ) {
			$this->append_script_and_deps_src( $payment_method_script );
		}
	}

	$this->scripts_to_lazy_load['wc-block-mini-cart-component-frontend'] = array(
		'src'          => $script_data['src'],
		'version'      => $script_data['version'],
		'translations' => $this->get_inner_blocks_translations(),
	);

	$this->asset_data_registry->add(
		'mini_cart_block_frontend_dependencies',
		$this->scripts_to_lazy_load,
		true
	);

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

	$template_part_edit_uri = '';

	if (
		current_user_can( 'edit_theme_options' ) &&
		wc_current_theme_is_fse_theme()
	) {
		$theme_slug      = BlockTemplateUtils::theme_has_template_part( 'mini-cart' ) ? wp_get_theme()->get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG;
		$site_editor_uri = admin_url( 'site-editor.php' );

		if ( version_compare( get_bloginfo( 'version' ), '5.9', '<' ) ) {
			$site_editor_uri = add_query_arg(
				array( 'page' => 'gutenberg-edit-site' ),
				admin_url( 'themes.php' )
			);
		}

		$template_part_edit_uri = 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.
	 */
	do_action( 'woocommerce_blocks_cart_enqueue_data' );
}