Automattic\WooCommerce\LayoutTemplates

LayoutTemplateRegistry::get_layout_template_instance()privateWC 1.0

Instantiate a single layout template and return it.

Method of the class: LayoutTemplateRegistry{}

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->get_layout_template_instance( $layout_template_info ): BlockTemplateInterface;
$layout_template_info(array) (required)
Layout template info.

LayoutTemplateRegistry::get_layout_template_instance() code WC 8.9.0

private function get_layout_template_instance( $layout_template_info ): BlockTemplateInterface {
	$class_name = $layout_template_info['class_name'];

	// Return the instance if it already exists.

	$layout_template_instance = isset( $this->layout_template_instances[ $class_name ] )
		? $this->layout_template_instances[ $class_name ]
		: null;

	if ( ! empty( $layout_template_instance ) ) {
		return $layout_template_instance;
	}

	// Instantiate the layout template.

	$layout_template_instance                       = new $class_name();
	$this->layout_template_instances[ $class_name ] = $layout_template_instance;

	// Call the after instantiation hooks.

	/**
	 * Fires after a layout template is instantiated.
	 *
	 * @param string $layout_template_id Layout template ID.
	 * @param string $layout_template_area Layout template area.
	 * @param BlockTemplateInterface $layout_template Layout template instance.
	 *
	 * @since 8.6.0
	 */
	do_action( 'woocommerce_layout_template_after_instantiation', $layout_template_info['id'], $layout_template_info['area'], $layout_template_instance );

	// Call the old, deprecated, register hook.
	wc_do_deprecated_action( 'woocommerce_block_template_register', array( $layout_template_instance ), '8.6.0', 'woocommerce_layout_template_after_instantiation' );

	return $layout_template_instance;
}