Issue using getBlockTypeHandle() programatically with block from scrapbook

Hi, I am getting the block type handle using getBlockTypeHandle(), so I can wrap HTML around certain blocks.

The issue I have encountered is that if a block is pasted from the scrapbook, it returns the handle of core_scrapbook_display.

Apparently this is because it is a “proxy block”:
https://documentation.concretecms.org/api/8.5.2/Concrete/Block/CoreScrapbookDisplay.html

I need to identify the type of every block, here is my code:


$mainBlocks = $c->getBlocks('Main');
        foreach ($mainBlocks as $b) {
           // Wrap all blocks except for:
           $handle = $b->getBlockTypeHandle();
           if ($handle == 'content_with_images' || $handle == 'msm_slider' || $handle == 'parallax_content' || $handle == 'google_api_map' || $handle == 'client_testimonials_carousel' || $handle == 'msm_image_banner') {
              $b->display();               
           }
           else {
              echo '<section class="content"><div class="container">';
              $b->display();
              echo '</div></section>';
           }
        }

How can I identify the block type of these blocks that are just returning core_scrapbook_display ?

Thanks

Shot in the dark here… What happens if you get the scrapbook display controller and call $b->getOriginalBlockID() ??

1 Like

@madesimplemedia, @EvanCooper liking my comment has me wondering if we’re not onto something. I’ll have to give this some poking when I have a moment if you don’t get to it first. I ran into similar issues when I wrote my Enlil Page Tease package. When teasing blocks from an area on one page to another, I wasn’t able to conjure what blocks were inside scrapbook_displays. I ended up going in a roundabout to force users to edit/save said scrapbook blocks before they will properly render in the teased output. Would love to be able to update my package also :slight_smile:

@enlil We’re finding the same with stacks. It will set a default handle of “core_stack_display“ until you edit that stack element: then it will create a new element with the right handle. We’re working on a way to programatically save the blocks when the page is saved/published.

The core does the following

if ($b && !$b->isError() && $b->getBlockTypeHandle() === BLOCK_HANDLE_SCRAPBOOK_PROXY) {
    $bi = $b->getInstance();
    $b = Block::getByID($bi->getOriginalBlockID());
}
2 Likes