Override Image Block Controller
Permalink 2 users found helpful
Well I have checked the how-to for overrides.
I'm trying to create a package where I need to override image block. While looking into the view.php, it only calls a method getContentAndGenerate()
I'm in a need to override it. So I just copy it and put it in my packages block folder. But it doesn't work at all.
Here is the code:
Am I doing anything wrong? Just check another add-on which overrides the content block & done the same process.
Rony
I'm trying to create a package where I need to override image block. While looking into the view.php, it only calls a method getContentAndGenerate()
I'm in a need to override it. So I just copy it and put it in my packages block folder. But it doesn't work at all.
Here is the code:
<?php defined('C5_EXECUTE') or die("Access Denied."); class ImageBlockController extends BlockController { function getContentAndGenerateCustom($align = false, $style = false, $id = null) { echo 'test'; $c = Page::getCurrentPage(); $bID = $this->bID; $f = $this->getFileObject(); $fullPath = $f->getPath(); $relPath = $f->getRelativePath(); $size = @getimagesize($fullPath); if (empty($size)) { echo t( 'Image Not Found. '); return ''; }
Viewing 15 lines of 54 lines. View entire code block.
Am I doing anything wrong? Just check another add-on which overrides the content block & done the same process.
Rony
I believe the core block controllers used to extend the BlockController object prior to 5.6.0. I just noticed these new objects that the core block controllers are now extending, but the howto still reflects the older objects.
It would sure be nice to see some documentation about this change and what we're supposed to do with it. I've got block overrides and custom blocks I created earlier, and I'm not sure whether I have to update them to extend the new objects, or if our custom blocks are still supposed to use the old ones.
It would sure be nice to see some documentation about this change and what we're supposed to do with it. I've got block overrides and custom blocks I created earlier, and I'm not sure whether I have to update them to extend the new objects, or if our custom blocks are still supposed to use the old ones.
I've also tried to use
but no luck
Rony
class ImageBlockController extends Concrete5_Controller_Block_Image {
but no luck
Rony
As well as declaring the class you will need to actually make it override by either
- placing it in the relevant root folder
Or
- calling overrodeCoreByPackage() from an on_ start() handler.
- placing it in the relevant root folder
Or
- calling overrodeCoreByPackage() from an on_ start() handler.
The root folder for the override should be /controllers
You mean I need to create a separate controller folder under packages directory?
No. That root /controllers folder applies to root level block controller overrides, not overrides from packages.
As far as I know, the place for a block controller override in a package would be in an identical structure to if the block was part of the package.
As far as I know, the place for a block controller override in a package would be in an identical structure to if the block was part of the package.
Yes the block that I'm using is Image block. And I need to override the blocks controller through package.
Rony
Rony
In your package controller, set up an on_start handler that calls overrideCoreByPackage() to map the core to use your new controller.
Anyone who can help me, please?
Rony
Rony
Just had the same scenario where I wanted to override the image block's controller to add some additional methods. Cache was disabled however when calling the new methods it was error as they didn't appear to exist.
For anyone else who stumbles across this, taking JohntheFish's advice I added the following to my packages on_start method which resolved the issue so many thanks John for pointing me in the right direction.
For anyone else who stumbles across this, taking JohntheFish's advice I added the following to my packages on_start method which resolved the issue so many thanks John for pointing me in the right direction.
public function on_start() { $objPkg = Loader::package($this->pkgHandle); $objEnv = Environment::get(); $objEnv->overrideCoreByPackage('blocks/image/controller.php', $objPkg); }
but you are extending the 'BlockController':