| 458 | * Determine whether a block is top-level or a child block. |
| 459 | * |
| 460 | * @param object $block The block in question. |
| 461 | * |
| 462 | * @return bool True if the block is top-level; false if it is a child block that can only be used within other blocks in the plugin. |
| 463 | */ |
| 464 | public function is_top_level_block( $block ) { |
| 465 | $ancestors = $block->parent ?? []; |
| 466 | $ancestors = array_merge( $ancestors, $block->ancestor ?? [] ); |
| 467 | |
| 468 | // If it has no parent or ancestor blocks, it's top-level. |
| 469 | if ( empty( $ancestors ) ) { |
| 470 | return true; |
| 471 | } |
| 472 | |
| 473 | foreach ( $ancestors as $ancestor_block_name ) { |
| 474 | // If it has an ancestor outside of this plugin, like `core/column`, then it's also top-level. |
| 475 | if ( ! isset( $this->blocks[ $ancestor_block_name ] ) ) { |
| 476 | return true; |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | return false; |
| 481 | } |
| 482 | |
| 483 | /** |