Automattic\WooCommerce\Internal\Admin\BlockTemplates
AbstractBlock::validate
Validate block configuration.
Метод класса: AbstractBlock{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->validate( $config, $root_template, ?ContainerInterface $parent );
- $config(массив) (обязательный)
- The block configuration.
- $root_template(BlockTemplateInterface) (обязательный)
- The block template that this block belongs to.
- ?ContainerInterface $parent(передается по ссылке — &)
- .
По умолчанию: null
Код AbstractBlock::validate() AbstractBlock::validate WC 10.3.5
protected function validate( array $config, BlockTemplateInterface &$root_template, ?ContainerInterface &$parent = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.parentFound
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.' );
}
}