get content of block as array

Permalink
the way blocks are handled in concrete5 is still not totally clear to me :(

let's say i have some self-made block type with the following fields:

name
phone
bio

i know that one instance of this block on the site has the id of 7. so i grab the block in my code like so:

$block = Block::getByID(7);


what i get if i look at $block in FirePHP is some massive nested object structure that is basically unreadable.

all i need is the unrendered content of this block like some kind of array plus the id of the page the block is currently on:

name: Lisa
phone: 123
bio: <p>blablabla.</p>


somehow this simple information seems impossible to get...!

nerdess
 
jero replied on at Permalink Reply
jero
I'm not sure quite why you're trying to do this, but you do something like this:

$block = Block::getByID(81);
var_dump($block->instance->getRecord()->_original);


You'll need to to add a getRecord method into the block controller, since the record property is protected and you can't access it directly:

function getRecord() {
    return $this->record;
}


You should then end up with an array of properties that get set on each block. I tried this with the Autonav block, and with one I created using the designer content package (if you're not using this, check it out, it's awesome)
nerdess replied on at Permalink Reply
nerdess
Cool yeah this works, I wanted to use the getRecord() method before but was wondering why it didn't work. Now it makes sense!

The reason why I want to do this is that I have blocks of my self-created type "job block" on a page. now what i want is to create a list of the latest jobs on the homepage with a link to the job block.

that is why i am scraping that page for blocks of the type "job block"...tho maybe i am overcomplicating it....not sure!