Automattic\WooCommerce\Blocks\BlockTypes

AbstractBlock::register_block_typeprotectedWC 1.0

Registers the block type with WordPress.

Method of the class: AbstractBlock{}

No Hooks.

Returns

String[]. Chunks paths.

Usage

// protected - for code of main (parent) or child class
$result = $this->register_block_type();

AbstractBlock::register_block_type() code WC 10.5.0

protected function register_block_type() {
	$block_settings = [
		'render_callback' => $this->get_block_type_render_callback(),
		'editor_script'   => $this->get_block_type_editor_script( 'handle' ),
	];

	// Conditionally override these, otherwise rely on block.json metadata.
	if ( $this->get_block_type_style() ) {
		$block_settings['style'] = $this->get_block_type_style();
	}

	if ( $this->get_block_type_editor_style() ) {
		$block_settings['editor_style'] = $this->get_block_type_editor_style();
	}

	if ( isset( $this->api_version ) ) {
		$block_settings['api_version'] = intval( $this->api_version );
	}

	$metadata_path = $this->asset_api->get_block_metadata_path( $this->block_name );

	// Prefer to register with metadata if the path is set in the block's class.
	if ( ! empty( $metadata_path ) ) {
		register_block_type_from_metadata(
			$metadata_path,
			$block_settings
		);
		return;
	}

	/*
	 * Insert attributes and supports if we're not registering the block using metadata.
	 * These are left unset until now and only added here because if they were set when registering with metadata,
	 * the attributes and supports from $block_settings would override the values from metadata.
	 */
	$block_settings['attributes']   = $this->get_block_type_attributes();
	$block_settings['supports']     = $this->get_block_type_supports();
	$block_settings['uses_context'] = $this->get_block_type_uses_context();

	register_block_type(
		$this->get_block_type(),
		$block_settings
	);
}