I’m trying to prepend a custom block to an existing collection of blocks. This is the code I’m using:
$chapterTitle = new Block([
‘type’ => ‘heading’,
‘content’ => [‘level’=>‘h2’, ‘text’=>$chap->title()]
]);
$blocks = $chap->content_blocks()->toBlocks();
$blocks->prepend( $chapterTitle );
The chapter title block exists when looping over $blocks but it does not have any siblings, so the block->next() returns null.
The first of block of the original collection also returns null on block->prev()
I’ve tried to ->add() instead of prepend but the same problem comes up.
Am I missing something?