How to call a block controller custom public method?
Permalink 1 user found helpful
My block controller is like this :
From another block, I want to check the state of all MCQ blocks on the current page.
The problem is that the getController method gives me a generic BlockController and I obtain the following error
How to cast the generic BlockController into a MCQ BlockController in order to call the method getAnswerState? If this is not possible what is the concrete5.7 way of doing this?
Thank you, any ideas are welcome.
<?php namespace Application\Block\MCQ; use Concrete\Core\Block\BlockController; class Controller extends BlockController { private $answerState = ''; ..... public function getAnswerState(){ return $this->answerState; } }
From another block, I want to check the state of all MCQ blocks on the current page.
$blocks = Page::getCurrentPage()->getBlocks('MCQArea'); foreach ($blocks as $b) { echo $b->getController()->getAnswerState(); }
The problem is that the getController method gives me a generic BlockController and I obtain the following error
Call to undefined method Concrete\Block\Content\Controller::getAnswerState()
How to cast the generic BlockController into a MCQ BlockController in order to call the method getAnswerState? If this is not possible what is the concrete5.7 way of doing this?
Thank you, any ideas are welcome.
You'd wrap it in an if statement with $b->getBlockTypeHandle()