How to get a block controller?

When I get blocks from a specific page area with $page->getBlocks(‘Area name’) I get an array with block objects.

After that how can I get the block controller from the CoreConversation block?

I’m asking because on the controller of the CoreConversation block I want to call the getConversationsObject() method.


Didn’t test this, but it should get you in the right direction. Interested to see your final outcome. I’ve wanted to chase those counts down as well, but haven’t gotten around to it yet :slight_smile:

$blocks = $page->getBlocks('Area name');
foreach ($blocks as $b) {
	if ($b->getBlockTypeHandle() == 'core_conversation') {
		$bc = $b->getController();
		$convObj = $bc->getConversationObject();
		$convCount = $convObj->getConversationMessagesTotal();

1 Like

Hey. Thank you very much! It works like a charm. Except the method on the conversation object is called getConversationMessagesTotal()

@core77 Excellent stuff! Ya, I grabbed that method name from @EvanCooper comments on the other thread. Wasn’t certain if it was correct or not. I guess we got around to it! Time to put this to work :wink:

I’ve edited my original answer to reflect the correct getConversationMessagesTotal() to avoid future confusion…

1 Like