Automattic\WooCommerce\Internal\Admin\BlockTemplates
AbstractBlock::validate()
Validate block configuration.
Method of the class: AbstractBlock{}
No Hooks.
Return
null
. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->validate( $config, $root_template, $parent );
- $config(array) (required)
- The block configuration.
- $root_template(BlockTemplateInterface) (required)
- The block template that this block belongs to.
- $parent(ContainerInterface|null)
- The parent block container.
Default: null
AbstractBlock::validate() AbstractBlock::validate code WC 9.3.3
protected function validate( array $config, BlockTemplateInterface &$root_template, ContainerInterface &$parent = null ) { if ( isset( $parent ) && ( $parent->get_root_template() !== $root_template ) ) { throw new \ValueError( 'The parent block must belong to the same template as the block.' ); } if ( ! isset( $config[ self::NAME_KEY ] ) || ! is_string( $config[ self::NAME_KEY ] ) ) { throw new \ValueError( 'The block name must be specified.' ); } if ( isset( $config[ self::ORDER_KEY ] ) && ! is_int( $config[ self::ORDER_KEY ] ) ) { throw new \ValueError( 'The block order must be an integer.' ); } if ( isset( $config[ self::ATTRIBUTES_KEY ] ) && ! is_array( $config[ self::ATTRIBUTES_KEY ] ) ) { throw new \ValueError( 'The block attributes must be an array.' ); } }